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, vm_max;
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();
virtual size_type nb_dof() const
Return the total number of degrees of freedom.
void slice_vector_on_basic_dof_of_element(const mesh_fem &mf, const VEC1 &vec, size_type cv, VEC2 &coeff, size_type qmult1=size_type(-1), size_type qmult2=size_type(-1))
Given a mesh_fem.
Define the getfem::mesh_fem class.
void interpolation(const mesh_fem &mf_source, const mesh_fem &mf_target, const VECTU &U, VECTV &V, int extrapolation=0, double EPS=1E-10, mesh_region rg_source=mesh_region::all_convexes(), mesh_region rg_target=mesh_region::all_convexes())
interpolation/extrapolation of (mf_source, U) on mf_target.
virtual pfem fem_of_element(size_type cv) const
Return the basic fem associated with an element (if no fem is associated, the function will crash! us...
void compute_gradient(const mesh_fem &mf, const mesh_fem &mf_target, const VECT1 &UU, VECT2 &VV)
Compute the gradient of a field on a getfem::mesh_fem.
size_t size_type
used as the common size type in the library
virtual size_type nb_basic_dof() const
Return the total number of basic degrees of freedom (before the optional reduction).
Interpolation of fields from a mesh_fem onto another.
virtual dim_type get_qdim() const
Return the Q dimension.
void compute_hessian(const mesh_fem &mf, const mesh_fem &mf_target, const VECT1 &UU, VECT2 &VV)
Compute the hessian of a field on a getfem::mesh_fem.
structure passed as the argument of fem interpolation functions.
void interpolation_von_mises(const getfem::mesh_fem &mf_u, const getfem::mesh_fem &mf_vm, const VEC1 &U, VEC2 &VM, scalar_type mu=1)
Compute the Von-Mises stress of a field (only valid for linearized elasticity in 3D) ...
bool is_reduced() const
Return true if a reduction matrix is applied to the dofs.
GEneric Tool for Finite Element Methods.
std::shared_ptr< const getfem::virtual_fem > pfem
type of pointer on a fem description
Describe a finite element method linked to a mesh.
gmm::uint16_type short_type
used as the common short type integer in the library
pfem_precomp fem_precomp(pfem pf, bgeot::pstored_point_tab pspt, dal::pstatic_stored_object dep)
Handles precomputations for FEM.
const mesh & linked_mesh() const
Return a reference to the underlying mesh.
const dal::bit_vector & convex_index() const
Get the set of convexes where a finite element has been assigned.
void interpolation_von_mises_or_tresca(const getfem::mesh_fem &mf_u, const getfem::mesh_fem &mf_vm, const VEC1 &U, VEC2 &VM, const getfem::mesh_fem &mf_lambda, const VEC3 &lambda, const getfem::mesh_fem &mf_mu, const VEC3 &mu, bool tresca)
Compute the Von-Mises stress of a field (valid for linearized elasticity in 2D and 3D) ...
virtual ind_dof_ct ind_basic_dof_of_element(size_type cv) const
Give an array of the dof numbers a of convex.
void set_ii(size_type ii__)
change the current point (assuming a geotrans_precomp_ is used)
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation