14 return (E * nu) / ((1.0 + nu) * (1.0 - 2.0 * nu));
16 return (nu * E) / (1.0 - nu * nu);
21 return E / (2.0 * (1.0 + nu));
26 : param_name_(param_name)
32 for (
int i =
param_.size(); i <= index; ++i)
40 param_[index].set_unit_type(unit_type);
46 const double x = p(0);
47 const double y = p(1);
48 const double z = p.size() == 3 ? p(2) : 0;
50 return (*
this)(
x,
y,
z, t, index);
59 return tmp_param(
x,
y,
z, t, index);
63 : param_name_(param_name)
76 for (
int i = 0; i < params_array.size(); ++i)
79 for (
int i = 0; i <
params_.size(); ++i)
81 for (
int j =
params_.at(i).param_.size(); j <= index; ++j)
83 params_.at(i).param_.emplace_back();
86 params_.at(i).param_[index].init(params_array[i]);
87 params_.at(i).param_[index].set_unit_type(unit_type);
215 (*this)(0, 0) = 2 * mu + lambda;
216 (*this)(0, 1) = lambda;
219 (*this)(1, 1) = 2 * mu + lambda;
226 (*this)(0, 0) = 2 * mu + lambda;
227 (*this)(0, 1) = lambda;
228 (*this)(0, 2) = lambda;
233 (*this)(1, 1) = 2 * mu + lambda;
234 (*this)(1, 2) = lambda;
239 (*this)(2, 2) = 2 * mu + lambda;
261 0.0, 0.0, (1.0 - nu) / 2.0;
269 v, 1. - v, v, 0, 0, 0,
270 v, v, 1. - v, 0, 0, 0,
271 0, 0, 0, (1. - 2. * v) / 2., 0, 0,
272 0, 0, 0, 0, (1. - 2. * v) / 2., 0,
273 0, 0, 0, 0, 0, (1. - 2. * v) / 2.;
279 double Ex,
double Ey,
double Ez,
280 double nuXY,
double nuXZ,
double nuYZ,
281 double muYZ,
double muZX,
double muXY,
const std::string &stress_units)
286 double nuYX = nuXY * Ey / Ex;
287 double nuZX = nuXZ * Ez / Ex;
288 double nuZY = nuYZ * Ez / Ey;
290 Eigen::MatrixXd compliance;
291 compliance.setZero(6, 6);
292 compliance << 1 / Ex, -nuYX / Ey, -nuZX / Ez, 0, 0, 0,
293 -nuXY / Ex, 1 / Ey, -nuZY / Ez, 0, 0, 0,
294 -nuXZ / Ex, -nuYZ / Ey, 1 / Ez, 0, 0, 0,
295 0, 0, 0, 1 / (2 * muYZ), 0, 0,
296 0, 0, 0, 0, 1 / (2 * muZX), 0,
297 0, 0, 0, 0, 0, 1 / (2 * muXY);
306 double nuYX = nuXY * Ey / Ex;
308 Eigen::MatrixXd compliance;
309 compliance.setZero(3, 3);
310 compliance << 1.0 / Ex, -nuYX / Ey, 0.0,
311 -nuXY / Ex, 1.0 / Ey, 0.0,
312 0.0, 0.0, 1.0 / (2 * muXY);
317 double Et,
double Ea,
318 double nu_t,
double nu_a,
319 double Ga,
const std::string &stress_units)
324 Eigen::MatrixXd compliance;
325 compliance.setZero(6, 6);
326 compliance << 1 / Et, -nu_t / Et, -nu_a / Ea, 0, 0, 0,
327 -nu_t / Et, 1 / Et, -nu_a / Ea, 0, 0, 0,
328 -nu_a / Ea, -nu_a / Ea, 1 / Ea, 0, 0, 0,
329 0, 0, 0, 1 / Ga, 0, 0,
330 0, 0, 0, 0, 1 / Ga, 0,
331 0, 0, 0, 0, 0, (2 * (1 + nu_t)) / Et;
340 for (
int k = 0; k < DIM; ++k)
341 res += (*
this)(j, k) * strain[k];
377 double llambda = tmp1(
x,
y,
z, t, el_id);
378 double mmu = tmp2(
x,
y,
z, t, el_id);
397 assert(!std::isnan(lambda));
398 assert(!std::isnan(mu));
399 assert(!std::isinf(lambda));
400 assert(!std::isinf(mu));
405 const int size = is_volume ? 3 : 2;
415 if (params.count(
"young"))
417 set_e_nu(index, params[
"young"], params[
"nu"], stress_unit);
419 else if (params.count(
"E"))
421 set_e_nu(index, params[
"E"], params[
"nu"], stress_unit);
423 else if (params.count(
"lambda"))
429 mu_or_nu_[index].set_unit_type(stress_unit);
449 rho_.back().init(1.0);
454 assert(
rho_.size() == 1 || el_id <
rho_.size());
456 const auto &tmp =
rho_.size() == 1 ?
rho_[0] :
rho_[el_id];
457 const double res = tmp(
x,
y,
z, t, el_id);
458 assert(!std::isnan(res));
459 assert(!std::isinf(res));
465 for (
int i =
rho_.size(); i <= index; ++i)
470 if (params.count(
"rho"))
472 rho_[index].init(params[
"rho"]);
474 else if (params.count(
"density"))
476 rho_[index].init(params[
"density"]);
479 rho_[index].set_unit_type(density_unit);
488 assert(size == 2 || size == 3);
492 for (
const auto &m :
dir_)
494 assert(m.rows() == size && m.cols() == size);
499 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3>
FiberDirection::operator()(
double px,
double py,
double pz,
double x,
double y,
double z,
double t,
int el_id)
const
501 assert(
dir_.size() == 1 || el_id <
dir_.size());
503 const auto &tmp =
dir_.size() == 1 ?
dir_[0] :
dir_[el_id];
504 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3> res;
505 res.resize(tmp.rows(), tmp.cols());
506 for (
int i = 0; i < tmp.rows(); ++i)
508 for (
int j = 0; j < tmp.cols(); ++j)
510 res(i, j) = tmp(i, j)(
x,
y,
z, t, el_id);
512 assert(!std::isnan(res(i, j)));
513 assert(!std::isinf(res(i, j)));
499 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3>
FiberDirection::operator()(
double px,
double py,
double pz,
double x,
double y,
double z,
double t,
int el_id)
const {
…}
519 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6>
FiberDirection::stiffness_rotation_voigt(
double px,
double py,
double pz,
double x,
double y,
double z,
double t,
int el_id)
const
524 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3> rot = (*this)(px, py, pz,
x,
y,
z, t, el_id);
525 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6> res;
527 int dim = rot.rows();
529 static const double sqrt2 = std::sqrt(2.0);
544 res << rot(0, 0) * rot(0, 0), rot(0, 1) * rot(0, 1), rot(0, 2) * rot(0, 2), sqrt2 * rot(0, 1) * rot(0, 2), sqrt2 * rot(0, 0) * rot(0, 2), sqrt2 * rot(0, 0) * rot(0, 1),
545 rot(1, 0) * rot(1, 0), rot(1, 1) * rot(1, 1), rot(1, 2) * rot(1, 2), sqrt2 * rot(1, 1) * rot(1, 2), sqrt2 * rot(1, 0) * rot(1, 2), sqrt2 * rot(1, 0) * rot(1, 1),
546 rot(2, 0) * rot(2, 0), rot(2, 1) * rot(2, 1), rot(2, 2) * rot(2, 2), sqrt2 * rot(2, 1) * rot(2, 2), sqrt2 * rot(2, 0) * rot(2, 2), sqrt2 * rot(2, 0) * rot(2, 1),
547 sqrt2 * rot(1, 0) * rot(2, 0), sqrt2 * rot(1, 1) * rot(2, 1), sqrt2 * rot(1, 2) * rot(2, 2), rot(1, 1) * rot(2, 2) + rot(1, 2) * rot(2, 1), rot(1, 0) * rot(2, 2) + rot(1, 2) * rot(2, 0), rot(1, 0) * rot(2, 1) + rot(1, 1) * rot(2, 0),
548 sqrt2 * rot(0, 0) * rot(2, 0), sqrt2 * rot(0, 1) * rot(2, 1), sqrt2 * rot(0, 2) * rot(2, 2), rot(0, 1) * rot(2, 2) + rot(0, 2) * rot(2, 1), rot(0, 0) * rot(2, 2) + rot(0, 2) * rot(2, 0), rot(0, 0) * rot(2, 1) + rot(0, 1) * rot(2, 0),
549 sqrt2 * rot(0, 0) * rot(1, 0), sqrt2 * rot(0, 1) * rot(1, 1), sqrt2 * rot(0, 2) * rot(1, 2), rot(0, 1) * rot(1, 2) + rot(0, 2) * rot(1, 1), rot(0, 0) * rot(1, 2) + rot(0, 2) * rot(1, 0), rot(0, 0) * rot(1, 1) + rot(0, 1) * rot(1, 0);
519 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6>
FiberDirection::stiffness_rotation_voigt(
double px,
double py,
double pz,
double x,
double y,
double z,
double t,
int el_id)
const {
…}
557 for (
int i =
dir_.size(); i <= index; ++i)
562 if (dir.size() == 3 || dir.size() == 2)
564 const int size = dir.size();
565 assert(size ==
size_);
566 dir_[index].resize(size, size);
567 for (
int i = 0; i < size; ++i)
569 if (!dir[i].is_array() || dir[i].size() != size)
571 log_and_throw_error(fmt::format(
"Fiber must be {}x{}, row {} is {}", size, size, i, dir[i].dump()));
573 for (
int j = 0; j < size; ++j)
575 dir_[index](i, j).init(dir[i][j]);
576 dir_[index](i, j).set_unit_type(unit);
581 else if (dir.size() == 9 || dir.size() == 4)
583 const int size = dir.size() == 9 ? 3 : 2;
584 assert(size ==
size_);
585 dir_[index].resize(size, size);
586 for (
int i = 0; i < size; ++i)
588 for (
int j = 0; j < size; ++j)
590 dir_[index](i, j).init(dir[i * size + j]);
591 dir_[index](i, j).set_unit_type(unit);
596 else if (dir.empty())
599 for (
int i = 0; i <
size_; ++i)
601 for (
int j = 0; j <
size_; ++j)
603 dir_[index](i, j).init(i == j ? 1.0 : 0.0);
604 dir_[index](i, j).set_unit_type(unit);
616 template double ElasticityTensor::compute_stress<3>(
const std::array<double, 3> &strain,
const int j)
const;
617 template double ElasticityTensor::compute_stress<6>(
const std::array<double, 6> &strain,
const int j)
const;
std::vector< Eigen::Triplet< double > > entries
std::vector< utils::ExpressionValue > rho_
virtual void add_multimaterial(const int index, const json ¶ms, const std::string &density_unit)
virtual double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const
double operator()(int i, int j) const
void rotate_stiffness(const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6 > &rotation_mtx_voigt)
void resize(const int size)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6 > stiffness_tensor_
void set_from_entries(const std::vector< double > &entries, const std::string &stress_unit)
void set_from_young_poisson(const double young, const double poisson, const std::string &stress_unit)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6 > reference_stiffness_tensor_
void set_orthotropic(double Ex, double Ey, double Ez, double nuXY, double nuXZ, double nuYZ, double muYZ, double muZX, double muXY, const std::string &stress_unit)
double compute_stress(const std::array< double, DIM > &strain, const int j) const
void set_transversely_isotropic(double Et, double Ea, double nu_t, double nu_a, double Ga, const std::string &stress_units)
void set_from_lambda_mu(const double lambda, const double mu, const std::string &stress_unit)
void unrotate_stiffness()
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6 > stiffness_rotation_voigt(double px, double py, double pz, double x, double y, double z, double t, int el_id) const
std::vector< Eigen::Matrix< utils::ExpressionValue, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3 > > dir_
void resize(const int size)
void add_multimaterial(const int index, const json ¶ms, const std::string &unit)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3 > operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const
void add_multimaterial(const int index, const json ¶ms, const std::string &unit_type)
double operator()(const RowVectorNd &p, double t, int index) const
GenericMatParam(const std::string ¶m_name)
std::vector< utils::ExpressionValue > param_
const std::string param_name_
void add_multimaterial(const int index, const json ¶ms, const std::string &unit_type)
std::vector< GenericMatParam > params_
GenericMatParams(const std::string ¶m_name)
const std::string param_name_
std::vector< utils::ExpressionValue > mu_or_nu_
void lambda_mu(double px, double py, double pz, double x, double y, double z, double t, int el_id, double &lambda, double &mu) const
void set_e_nu(const int index, const json &E, const json &nu, const std::string &stress_unit)
std::vector< utils::ExpressionValue > lambda_or_E_
void add_multimaterial(const int index, const json ¶ms, const bool is_volume, const std::string &stress_unit)
Eigen::MatrixXd lambda_mat_
std::vector< T > json_as_array(const json &j)
Return the value of a json object as an array.
double convert_to_mu(const double E, const double nu)
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
double convert_to_lambda(const bool is_volume, const double E, const double nu)
void log_and_throw_error(const std::string &msg)