38 #ifndef GETFEM_DERIVATIVES_H__
39 #define GETFEM_DERIVATIVES_H__
61 template<
class VECT1,
class VECT2>
63 const VECT1 &UU, VECT2 &VV) {
64 typedef typename gmm::linalg_traits<VECT1>::value_type T;
69 size_type qqdimt = qdim * N / target_qdim;
73 mf.extend_vector(UU, U);
76 "meshes are different.");
77 GMM_ASSERT1(target_qdim == qdim*N || target_qdim == qdim
78 || target_qdim == 1,
"invalid Qdim for gradient mesh_fem");
83 bgeot::pgeotrans_precomp pgp = NULL;
84 pfem_precomp pfp = NULL;
85 pfem pf, pf_target, pf_old = NULL, pf_targetold = NULL;
88 for (dal::bv_visitor cv(mf_target.
convex_index()); !cv.finished(); ++cv) {
93 GMM_ASSERT1(!(pf_target->need_G()) && pf_target->is_lagrange(),
94 "finite element target not convenient");
96 bgeot::vectors_to_base_matrix(G, mf.
linked_mesh().points_of_convex(cv));
99 if (pf_targetold != pf_target) {
100 pgp = bgeot::geotrans_precomp(pgt, pf_target->node_tab(cv), pf_target);
102 pf_targetold = pf_target;
105 pfp =
fem_precomp(pf, pf_target->node_tab(cv), pf_target);
109 gmm::dense_matrix<T> grad(N,qdim), gradt(qdim,N);
115 for (
size_type j = 0; j < pf_target->nb_dof(cv); ++j) {
119 pf->interpolation_grad(ctx, coeff, gradt, dim_type(qdim));
120 gmm::copy(gmm::transposed(gradt),grad);
121 std::copy(grad.begin(), grad.end(), V.begin() + dof_t);
125 mf_target.reduce_vector(V, VV);
143 template<
class VECT1,
class VECT2>
145 const VECT1 &UU, VECT2 &VV) {
146 typedef typename gmm::linalg_traits<VECT1>::value_type T;
151 size_type qqdimt = qdim * N * N / target_qdim;
155 mf.extend_vector(UU, U);
158 "meshes are different.");
159 GMM_ASSERT1(target_qdim == qdim || target_qdim == 1,
160 "invalid Qdim for gradient mesh_fem");
162 std::vector<T> coeff;
164 bgeot::pgeotrans_precomp pgp = NULL;
165 pfem_precomp pfp = NULL;
166 pfem pf, pf_target, pf_old = NULL, pf_targetold = NULL;
169 for (dal::bv_visitor cv(mf_target.
convex_index()); !cv.finished(); ++cv) {
172 GMM_ASSERT1(!(pf_target->need_G()) && pf_target->is_lagrange(),
173 "finite element target not convenient");
175 bgeot::vectors_to_base_matrix(G, mf.
linked_mesh().points_of_convex(cv));
178 if (pf_targetold != pf_target) {
179 pgp = bgeot::geotrans_precomp(pgt, pf_target->node_tab(cv), pf_target);
181 pf_targetold = pf_target;
184 pfp =
fem_precomp(pf, pf_target->node_tab(cv), pf_target);
188 gmm::dense_matrix<T> hess(N*N,qdim), hesst(qdim,N*N);
194 for (
size_type j = 0; j < pf_target->nb_dof(cv); ++j) {
198 pf->interpolation_hess(ctx, coeff, hesst, dim_type(qdim));
199 gmm::copy(gmm::transposed(hesst), hess);
200 std::copy(hess.begin(), hess.end(), V.begin() + dof_t);
204 mf_target.reduce_vector(V, VV);
210 template <
typename VEC1,
typename VEC2>
213 const VEC1 &U, VEC2 &VM,
215 dal::bit_vector bv; bv.add(0, mf_vm.
nb_dof());
219 template <
typename VEC1,
typename VEC2>
222 const VEC1 &U, VEC2 &VM,
223 const dal::bit_vector &mf_vm_dofs,
228 std::vector<scalar_type> DU(mf_vm.
nb_dof() * N * N);
232 GMM_ASSERT1(!mf_vm.
is_reduced(),
"Sorry, to be done");
234 scalar_type vm_min = 0., vm_max = 0.;
235 for (dal::bv_visitor i(mf_vm_dofs); !i.finished(); ++i) {
237 scalar_type sdiag = 0.;
238 for (
unsigned j=0; j < N; ++j) {
239 sdiag += DU[i*N*N + j*N + j];
240 for (
unsigned k=0; k < N; ++k) {
241 scalar_type e = .5*(DU[i*N*N + j*N + k] + DU[i*N*N + k*N + j]);
245 VM[i] -= 1./N * sdiag * sdiag;
246 vm_min = (i == 0 ? VM[0] : std::min(vm_min, VM[i]));
247 vm_max = (i == 0 ? VM[0] : std::max(vm_max, VM[i]));
249 cout <<
"Von Mises : min=" << 4*mu*mu*vm_min <<
", max="
250 << 4*mu*mu*vm_max <<
"\n";
251 gmm::scale(VM, 4*mu*mu);
258 template <
typename VEC1,
typename VEC2,
typename VEC3>
261 const VEC1 &U, VEC2 &VM,
268 typedef typename gmm::linalg_traits<VEC1>::value_type T;
270 std::vector<T> GRAD(mf_vm.
nb_dof()*N*N),
272 base_matrix sigma(N,N);
278 GMM_ASSERT1(!mf_vm.
is_reduced(),
"Sorry, to be done");
279 GMM_ASSERT1(N>=2 && N<=3,
"Only for 2D and 3D");
282 scalar_type trE = 0, diag = 0;
283 for (
unsigned j = 0; j < N; ++j)
284 trE += GRAD[i*N*N + j*N + j];
286 diag = LAMBDA[i]*trE;
288 diag = (-2./3.)*MU[i]*trE;
289 for (
unsigned j = 0; j < N; ++j) {
290 for (
unsigned k = 0; k < N; ++k) {
291 scalar_type eps = (GRAD[i*N*N + j*N + k] +
292 GRAD[i*N*N + k*N + j]);
293 sigma(j,k) = MU[i]*eps;
301 VM[i] = sqrt((3./2.)*gmm::mat_euclidean_norm_sqr(sigma));
303 VM[i] = sqrt((3./2.)*(gmm::mat_euclidean_norm_sqr(sigma) + diag*diag));
306 gmm::symmetric_qr_algorithm(sigma, eig);
307 std::sort(eig.begin(), eig.end());
308 VM[i] = eig.back() - eig.front();