[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] (no subject)
From: |
Yves Renard |
Subject: |
[Getfem-commits] (no subject) |
Date: |
Fri, 1 Nov 2019 09:10:00 -0400 (EDT) |
branch: master
commit d9a232ba05182778ac4ae1be130dbe699d7848aa
Author: Yves Renard <address@hidden>
Date: Fri Nov 1 13:59:47 2019 +0100
small fixes for python3 compatibility
---
interface/src/gf_compute.cc | 14 ++++++---
.../python/demo_cracked_thermo_elastic_body.py | 2 +-
.../tests/python/demo_elastic_ring_contact.py | 6 ++--
.../tests/python/demo_finite_strain_plasticity.py | 12 ++++----
.../python/demo_finite_strain_plasticity_3D.py | 12 ++++----
interface/tests/python/demo_laplacian_DG.py | 2 +-
interface/tests/python/demo_laplacian_pyramid.py | 2 +-
.../tests/python/demo_large_sliding_contact.py | 2 +-
interface/tests/python/demo_parallel_laplacian.py | 36 +++++++++++-----------
interface/tests/python/demo_phase_field.py | 16 +++++-----
src/getfem_linearized_plates.cc | 2 +-
11 files changed, 55 insertions(+), 51 deletions(-)
diff --git a/interface/src/gf_compute.cc b/interface/src/gf_compute.cc
index 1942fd6..c32f8a2 100644
--- a/interface/src/gf_compute.cc
+++ b/interface/src/gf_compute.cc
@@ -127,7 +127,9 @@ gf_interpolate(getfemint::mexargs_in& in,
getfemint::mexargs_out& out,
dims.push_back(unsigned(mf_dest.nb_dof()));
dims.opt_transform_col_vect_into_row_vect();
garray<T> V = out.pop().create_array(dims,T());
- getfem::interpolation(mf, mf_dest, U, V);
+ std::vector<T> VV(V.size());
+ getfem::interpolation(mf, mf_dest, U, VV);
+ gmm::copy(VV, V);
}
else if (is_slice_object(in.front())) {
getfem::stored_mesh_slice *sl = to_slice_object(in.pop());
@@ -141,7 +143,9 @@ gf_interpolate(getfemint::mexargs_in& in,
getfemint::mexargs_out& out,
dims.push_back(unsigned(sl->nb_points()));
dims.opt_transform_col_vect_into_row_vect();
garray<T> V = out.pop().create_array(dims, T());
- sl->interpolate(mf, U, V);
+ std::vector<T> VV(V.size());
+ sl->interpolate(mf, U, VV);
+ gmm::copy(VV, V);
}
else {
size_type N = mf.linked_mesh().dim();
@@ -161,12 +165,12 @@ gf_interpolate(getfemint::mexargs_in& in,
getfemint::mexargs_out& out,
dims.push_back(unsigned(nbpoints));
dims.opt_transform_col_vect_into_row_vect();
garray<T> V = out.pop().create_array(dims,T());
-
+ std::vector<T> VV(V.size());
getfem::base_matrix Maux;
// cout << "begin interpolation, qmult = " << qmult << endl;
- getfem::interpolation(mf, mti, U, V, Maux, 0);
+ getfem::interpolation(mf, mti, U, VV, Maux, 0);
// cout << "end interpolation" << endl;
-
+ gmm::copy(VV, V);
}
// else THROW_BADARG("expecting a mesh_fem or a mesh_slice for
interpolation");
}
diff --git a/interface/tests/python/demo_cracked_thermo_elastic_body.py
b/interface/tests/python/demo_cracked_thermo_elastic_body.py
index dc4be68..6fe6015 100644
--- a/interface/tests/python/demo_cracked_thermo_elastic_body.py
+++ b/interface/tests/python/demo_cracked_thermo_elastic_body.py
@@ -29,7 +29,7 @@
import numpy as np
import getfem as gf
-np.set_printoptions(threshold=np.nan)
+np.set_printoptions(threshold=100000)
gf.util_trace_level(1)
# Parameters: #########################################################
diff --git a/interface/tests/python/demo_elastic_ring_contact.py
b/interface/tests/python/demo_elastic_ring_contact.py
index 26ba6fd..d172f3e 100644
--- a/interface/tests/python/demo_elastic_ring_contact.py
+++ b/interface/tests/python/demo_elastic_ring_contact.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
# Python GetFEM++ interface
#
# Copyright (C) 2013-2015 Konstantinos Poulios.
@@ -270,10 +270,10 @@ for nit in range(steps+1):
md.set_variable('wR', md.variable('uR'))
md.set_variable('wB', md.variable('uB'))
- starttime = time.clock()
+ starttime = time.process_time()
md.solve('noisy', 'max_iter', 40, 'max_res', 1e-8, #)[0]
'lsearch', 'simplest', 'alpha max ratio', 1.5, 'alpha min', 0.2,
'alpha mult', 0.6)[0]
- print('solution time for iteration %i is %f sec' % (nit,
time.clock()-starttime))
+ print('solution time for iteration %i is %f sec' % (nit,
time.process_time()-starttime))
U_R = md.variable('uR')
VM_R = md.compute_Von_Mises_or_Tresca('uR', lawname, 'params_ring1', mfvm_R)
diff --git a/interface/tests/python/demo_finite_strain_plasticity.py
b/interface/tests/python/demo_finite_strain_plasticity.py
index e8bdb37..a6d4552 100644
--- a/interface/tests/python/demo_finite_strain_plasticity.py
+++ b/interface/tests/python/demo_finite_strain_plasticity.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
#
# Copyright (C) 2014-2018 Konstantinos Poulios.
#
@@ -27,7 +27,7 @@ import os
import time
import shutil
-np.set_printoptions(threshold=np.nan)
+np.set_printoptions(threshold=100000)
gf.util_trace_level(1)
# Input data
@@ -248,7 +248,7 @@ mf_dirichlet_mult =
md.mesh_fem_of_variable(dirichlet_multname)
mass_mat = gf.asm_mass_matrix(mim, mfout)
shutil.copyfile(os.path.abspath(sys.argv[0]),resultspath+'/'+sys.argv[0])
-starttime_overall = time.clock()
+starttime_overall = time.process_time()
with open('%s/finite_strain_plasticity_forces.dat' % resultspath, 'w') as f:
for step in range(0,steps+1):
print('Solving step: %i' % step)
@@ -257,7 +257,7 @@ with open('%s/finite_strain_plasticity_forces.dat' %
resultspath, 'w') as f:
dirichlet_data =
mf_dirichlet_mult.eval(dirichlet_str.format(step),globals(),locals())
md.set_variable('dirichlet_data', dirichlet_data)
- starttime = time.clock()
+ starttime = time.process_time()
iters = 41
nit = \
md.solve('noisy', 'lsolver', 'mumps', 'max_iter', iters, 'max_res',
1e-10, #)[0]
@@ -270,7 +270,7 @@ with open('%s/finite_strain_plasticity_forces.dat' %
resultspath, 'w') as f:
md.set_variable('dirichlet_data', dirichlet_data)
md.solve('noisy', 'lsolver', 'mumps', 'max_iter', iters, 'max_res',
1e-10, #)[0]
'lsearch', 'simplest', 'alpha max ratio', 1.5, 'alpha min',
0.05, 'alpha mult', 0.6)[0]
- print('STEP %i COMPLETED IN %f SEC' % (step, time.clock()-starttime))
+ print('STEP %i COMPLETED IN %f SEC' % (step,
time.process_time()-starttime))
VM = md.compute_finite_strain_elastoplasticity_Von_Mises\
(mim, mfout, "Simo_Miehe",
"displacement_and_plastic_multiplier_and_pressure",
@@ -315,4 +315,4 @@ with open('%s/finite_strain_plasticity_forces.dat' %
resultspath, 'w') as f:
dfR[0::N].sum()/H, dfR[1::N].sum()/H))
f.flush()
-print('OVERALL SOLUTION TIME IS %f SEC' % (time.clock()-starttime_overall))
+print('OVERALL SOLUTION TIME IS %f SEC' %
(time.process_time()-starttime_overall))
diff --git a/interface/tests/python/demo_finite_strain_plasticity_3D.py
b/interface/tests/python/demo_finite_strain_plasticity_3D.py
index 5febab2..ef4e7ac 100644
--- a/interface/tests/python/demo_finite_strain_plasticity_3D.py
+++ b/interface/tests/python/demo_finite_strain_plasticity_3D.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
#
# Copyright (C) 2014-2018 Konstantinos Poulios.
#
@@ -27,7 +27,7 @@ import os
import time
import shutil
-np.set_printoptions(threshold=np.nan)
+np.set_printoptions(threshold=100000)
gf.util_trace_level(1)
# Input data
@@ -246,7 +246,7 @@ mf_dirichlet_mult =
md.mesh_fem_of_variable(dirichlet_multname)
mass_mat = gf.asm_mass_matrix(mim, mfout)
shutil.copyfile(os.path.abspath(sys.argv[0]),resultspath+'/'+sys.argv[0])
-starttime_overall = time.clock()
+starttime_overall = time.process_time()
with open('%s/finite_strain_plasticity_forces.dat' % resultspath, 'w') as f:
for step in range(0,steps+1):
print('Solving step: %i' % step)
@@ -255,7 +255,7 @@ with open('%s/finite_strain_plasticity_forces.dat' %
resultspath, 'w') as f:
dirichlet_data =
mf_dirichlet_mult.eval(dirichlet_str.format(step),globals(),locals())
md.set_variable('dirichlet_data', dirichlet_data)
- starttime = time.clock()
+ starttime = time.process_time()
iters = 41
nit = \
md.solve('noisy', 'lsolver', 'mumps', 'max_iter', iters, 'max_res',
1e-10, #)[0]
@@ -268,7 +268,7 @@ with open('%s/finite_strain_plasticity_forces.dat' %
resultspath, 'w') as f:
md.set_variable('dirichlet_data', dirichlet_data)
md.solve('noisy', 'lsolver', 'mumps', 'max_iter', iters, 'max_res',
1e-10, #)[0]
'lsearch', 'simplest', 'alpha max ratio', 1.5, 'alpha min',
0.05, 'alpha mult', 0.6)[0]
- print('STEP %i COMPLETED IN %f SEC' % (step, time.clock()-starttime))
+ print('STEP %i COMPLETED IN %f SEC' % (step,
time.process_time()-starttime))
VM = md.compute_finite_strain_elastoplasticity_Von_Mises\
(mim, mfout, "Simo_Miehe",
"displacement_and_plastic_multiplier_and_pressure",
@@ -313,4 +313,4 @@ with open('%s/finite_strain_plasticity_forces.dat' %
resultspath, 'w') as f:
dfR[0::N].sum()/H, dfR[1::N].sum()/H))
f.flush()
-print('OVERALL SOLUTION TIME IS %f SEC' % (time.clock()-starttime_overall))
+print('OVERALL SOLUTION TIME IS %f SEC' %
(time.process_time()-starttime_overall))
diff --git a/interface/tests/python/demo_laplacian_DG.py
b/interface/tests/python/demo_laplacian_DG.py
index 921f769..4810a33 100644
--- a/interface/tests/python/demo_laplacian_DG.py
+++ b/interface/tests/python/demo_laplacian_DG.py
@@ -64,7 +64,7 @@ tleft = abs(fnor[1,:]+1) < 1e-14
ttop = abs(fnor[0,:]-1) < 1e-14
fleft = np.compress(tleft, flst, axis=1)
ftop = np.compress(ttop, flst, axis=1)
-fneum = np.compress(True - ttop - tleft, flst, axis=1)
+fneum = np.compress(np.logical_not(ttop + tleft), flst, axis=1)
# Mark it as boundary
DIRICHLET_BOUNDARY_NUM1 = 1
diff --git a/interface/tests/python/demo_laplacian_pyramid.py
b/interface/tests/python/demo_laplacian_pyramid.py
index 50abe33..c6b4c4e 100644
--- a/interface/tests/python/demo_laplacian_pyramid.py
+++ b/interface/tests/python/demo_laplacian_pyramid.py
@@ -75,7 +75,7 @@ tleft = abs(fnor[1,:]+1) < 1e-14
ttop = abs(fnor[0,:]-1) < 1e-14
fleft = np.compress(tleft, flst, axis=1)
ftop = np.compress(ttop, flst, axis=1)
-fneum = np.compress(True - ttop - tleft, flst, axis=1)
+fneum = np.compress(np.logical_not(ttop + tleft), flst, axis=1)
# Mark it as boundary
DIRICHLET_BOUNDARY_NUM1 = 1
diff --git a/interface/tests/python/demo_large_sliding_contact.py
b/interface/tests/python/demo_large_sliding_contact.py
index 4576514..86494eb 100644
--- a/interface/tests/python/demo_large_sliding_contact.py
+++ b/interface/tests/python/demo_large_sliding_contact.py
@@ -26,7 +26,7 @@ import numpy as np
gf.util_trace_level(1)
-test_case = 3 # 0 = 2D punch on a rigid obstacle
+test_case = 1 # 0 = 2D punch on a rigid obstacle
# 1 = 2D punch on a deformable obstacle (one slave, one master)
# 2 = 2D with two different meshes
# 3 = 2D with multi-body and only one mesh
diff --git a/interface/tests/python/demo_parallel_laplacian.py
b/interface/tests/python/demo_parallel_laplacian.py
index 5a01ed0..3e72cf0 100644
--- a/interface/tests/python/demo_parallel_laplacian.py
+++ b/interface/tests/python/demo_parallel_laplacian.py
@@ -47,13 +47,13 @@ Dirichlet_with_multipliers = True # Dirichlet condition
with multipliers
# or penalization
dirichlet_coefficient = 1e10 # Penalization coefficient
-t = time.clock()
+t = time.process_time()
# creation of a simple cartesian mesh
m = gf.Mesh('regular_simplices', np.arange(0,1+1./NX,1./NX),
np.arange(0,1+1./NX,1./NX))
if (rank == 0):
- print('Time for building mesh', time.clock()-t)
-t = time.clock()
+ print('Time for building mesh', time.process_time()-t)
+t = time.process_time()
# create a MeshFem for u and rhs fields of dimension 1 (i.e. a scalar field)
mfu = gf.MeshFem(m, 1)
@@ -72,7 +72,7 @@ tleft = abs(fnor[1,:]+1) < 1e-14
ttop = abs(fnor[0,:]-1) < 1e-14
fleft = np.compress(tleft, flst, axis=1)
ftop = np.compress(ttop, flst, axis=1)
-fneum = np.compress(True - ttop - tleft, flst, axis=1)
+fneum = np.compress(np.logical_not(ttop + tleft), flst, axis=1)
# mark it as boundary
DIRICHLET_BOUNDARY_NUM1 = 1
@@ -83,16 +83,16 @@ m.set_region(DIRICHLET_BOUNDARY_NUM2, ftop)
m.set_region(NEUMANN_BOUNDARY_NUM, fneum)
if (rank == 0):
- print('Time for building fem and im', time.clock()-t)
-t = time.clock()
+ print('Time for building fem and im', time.process_time()-t)
+t = time.process_time()
nb_dof = mfu.nbdof()
if (rank == 0):
print('Nb dof for the main unknown: ', nb_dof)
if (rank == 0):
- print('Time for dof numbering', time.clock()-t)
-t = time.clock()
+ print('Time for dof numbering', time.process_time()-t)
+t = time.process_time()
# interpolate the exact solution (Assuming mfu is a Lagrange fem)
@@ -103,8 +103,8 @@ F1 = mfrhs.eval('-(2*(x*x+y*y)-2*x-2*y+20*x*x*x)')
F2 = mfrhs.eval('[y*(y-1)*(2*x-1) + 5*x*x*x*x, x*(x-1)*(2*y-1)]')
if (rank == 0):
- print('Time for python interpolation', time.clock()-t)
-t = time.clock()
+ print('Time for python interpolation', time.process_time()-t)
+t = time.process_time()
# model
md = gf.Model('real')
@@ -149,8 +149,8 @@ else:
'DirichletData')
if (rank == 0):
- print('Time for model building', time.clock()-t)
-t = time.clock()
+ print('Time for model building', time.process_time()-t)
+t = time.process_time()
md.nbdof
nb_dof = md.nbdof()
@@ -158,15 +158,15 @@ if (rank == 0):
print('Nb dof for the model: ', nb_dof)
if (rank == 0):
- print('Time for model actualize sizes', time.clock()-t)
-t = time.clock()
+ print('Time for model actualize sizes', time.process_time()-t)
+t = time.process_time()
# assembly of the linear system and solve.
md.solve()
if (rank == 0):
- print('Time for model solve', time.clock()-t)
-t = time.clock()
+ print('Time for model solve', time.process_time()-t)
+t = time.process_time()
# main unknown
U = md.variable('u')
@@ -178,8 +178,8 @@ if (rank == 0):
print('Error in H1 norm : ', H1error)
if (rank == 0):
- print('Time for error computation', time.clock()-t)
-t = time.clock()
+ print('Time for error computation', time.process_time()-t)
+t = time.process_time()
# export data
diff --git a/interface/tests/python/demo_phase_field.py
b/interface/tests/python/demo_phase_field.py
index 9bd14fa..90f9eda 100644
--- a/interface/tests/python/demo_phase_field.py
+++ b/interface/tests/python/demo_phase_field.py
@@ -24,7 +24,7 @@ import getfem as gf
import numpy as np
import os
-np.set_printoptions(threshold=np.nan)
+np.set_printoptions(threshold=100000)
gf.util_trace_level(1)
# Input data
@@ -55,8 +55,8 @@ integration_degree = 5 # 9 gauss points per quad
#------------------------------------
-NX = 2*((NX+1)/2)
-NY = 2*((NY+1)/2)
+NX = int(2*((NX+1)/2))
+NY = int(2*((NY+1)/2))
resultspath = "./demo_phase_field_results"
if not os.path.exists(resultspath):
@@ -67,15 +67,15 @@ B_BOUNDARY = 4
T_BOUNDARY = 6
TB_BOUNDARY = 7
-NX_seed1 = np.linspace(-1, 0, NX/3+1)
-NX_seed2 = np.linspace(0, 1, (NX-NX/3)+1)[1:]
-NY_seed = np.linspace(-1, 1, NY+1)
+NX_seed1 = np.linspace(-1., 0., int(NX/3+1))
+NX_seed2 = np.linspace(0., 1., int((NX-NX/3)+1))[1:]
+NY_seed = np.linspace(-1., 1., NY+1)
X_seed1 =
LX/2*(0.2*NX_seed1+0.8*np.sign(NX_seed1)*np.power(np.abs(NX_seed1),1.5))
X_seed2 =
LX/2*(0.6*NX_seed2+0.4*np.sign(NX_seed2)*np.power(np.abs(NX_seed2),1.5))
X_seed = np.concatenate((X_seed1,X_seed2))
Y_seed = LY/2*(0.2*NY_seed+0.8*np.sign(NY_seed)*np.power(np.abs(NY_seed),1.5))
-m1 = gf.Mesh("cartesian", X_seed, Y_seed[0:NY/2+1])
-m2 = gf.Mesh("cartesian", X_seed, Y_seed[NY/2:])
+m1 = gf.Mesh("cartesian", X_seed, Y_seed[0:int(NY/2+1)])
+m2 = gf.Mesh("cartesian", X_seed, Y_seed[int(NY/2):])
gap = 1e-5
pts = m1.pts()
for i in range(pts.shape[1]):
diff --git a/src/getfem_linearized_plates.cc b/src/getfem_linearized_plates.cc
index a984f35..419eea9 100644
--- a/src/getfem_linearized_plates.cc
+++ b/src/getfem_linearized_plates.cc
@@ -227,7 +227,7 @@ namespace getfem {
}
std::stringstream fem_desc;
- fem_desc << "FEM_RT0" << (simplex ? "P":"Q") << "(" << N << ")";
+ fem_desc << "FEM_RT0" << (simplex ? "":"Q") << "(" << N << ")";
pfem pf2 = fem_descriptor(fem_desc.str());
// Obtaining a convenient integration method