Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
elasticity.cpp
Go to the documentation of this file.
1#include <cfloat>
2#include <FiniteElement.h>
3#include <WeakProblem.h>
4#include <cmath>
5using namespace model;
6
7Eigen::VectorXd solveElasticity(std::shared_ptr<SimplicialMesh<3>> mesh)
8{
10 auto fe = std::make_shared<FE>(mesh);
11 auto u = fe->trial<3>(); // displacement
12 const double mu = 1.0, nu = 0.3;
13 const double lambda = 2*mu*nu/(1-2*nu);
14 Eigen::Matrix<double,6,6> C = Eigen::Matrix<double,6,6>::Zero();
15 C.topLeftCorner<3,3>().setConstant(lambda);
16 C.diagonal().head<3>().array() += 2*mu;
17 C.diagonal().tail<3>().setConstant(mu); // engineering shear strain
18
19 for (size_t n=0; n<fe->nodeSize(); ++n)
20 if (std::abs(fe->node(n).P0(0)-mesh->xMin()(0)) < 1.e-10)
21 for (int c=0; c<3; ++c)
22 u->dirichletConditions()[3*n+c] = 0.0; // clamp x-min face
23
24 auto dV = fe->domain<EntireDomain,4,GaussLegendre>();
25 auto e = def(u);
26 auto stiffness = (test(e), C*e)*dV;
27 const Eigen::Vector3d force(0.0, 0.0, -1.e-3); // body force per volume
28 auto load = (test(u), make_constant(force))*dV;
29 auto problem = weakProblem(stiffness, load);
30 problem->solveWithMasterSlaveConstraints(); // assemble, constrain, solve
31 return u->dofVector(); // three entries per FE node
32}
Eigen::VectorXd solveElasticity(std::shared_ptr< SimplicialMesh< 3 > > mesh)
Definition elasticity.cpp:7
c
Definition int_R.m:15
auto def(const std::shared_ptr< T > &x)
Definition TrialDef.h:64
auto weakProblem(std::shared_ptr< BWF > bwf, std::shared_ptr< LWF > lwf, WeakProblemOptions options={})
auto make_constant(const Eigen::Matrix< double, rows, cols > &c)
Definition Constant.h:44
Class template defining the GaussLegendre rules for determination of quadrature abscissas and weights...
const double mu
const double nu
REAL u[4]
int e