https://mooseframework.inl.gov
HomogenizationInterface.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "InputParameters.h"
13 #include "Function.h"
14 
15 // Helpers common to the whole homogenization system
16 namespace Homogenization
17 {
18 // Moose constraint type, for input
19 const MultiMooseEnum constraintType("strain stress none");
20 
22 enum class ConstraintType
23 {
24  Strain,
25  Stress,
26  None
27 };
28 
29 using ConstraintMap =
30  std::map<std::pair<unsigned int, unsigned int>, std::pair<ConstraintType, const Function *>>;
31 }
32 
36 template <class T>
37 class HomogenizationInterface : public T
38 {
39 public:
41 
42  HomogenizationInterface(const InputParameters & parameters);
43 
44 protected:
46  const Homogenization::ConstraintMap & cmap() const { return _cmap; }
47 
48 private:
51 };
52 
53 template <class T>
56 {
59  "constraint_types",
61  "Type of each constraint: strain, stress, or none. The types are specified in the "
62  "column-major order, and there must be 9 entries in total.");
63  params.addRequiredParam<std::vector<FunctionName>>(
64  "targets", "Functions giving the targets to hit for constraint types that are not none.");
65  return params;
66 }
67 
68 template <class T>
70  : T(parameters)
71 {
72  // Constraint types
73  auto types = parameters.get<MultiMooseEnum>("constraint_types");
74  if (types.size() != Moose::dim * Moose::dim)
75  this->paramError("constraint_types",
76  "Number of constraint types must equal ",
78  ", but ",
79  types.size(),
80  " are provided.");
81 
82  // Targets to hit
83  const std::vector<FunctionName> & fnames = parameters.get<std::vector<FunctionName>>("targets");
84 
85  // Prepare the constraint map
86  unsigned int fcount = 0;
87  for (const auto j : make_range(Moose::dim))
88  for (const auto i : make_range(Moose::dim))
89  {
90  const auto idx = i + Moose::dim * j;
91  const auto ctype = static_cast<Homogenization::ConstraintType>(types.get(idx));
93  {
94  if (fcount >= fnames.size())
95  this->paramError(
96  "targets",
97  "Number of target functions must equal the number of non-none constraint "
98  "types. Only ",
99  fnames.size(),
100  " are provided.");
101  const Function * const f = &this->getFunctionByName(fnames[fcount++]);
102  _cmap[{i, j}] = {ctype, f};
103  }
104  }
105 
106  // Make sure there aren't unused targets
107  if (fcount != fnames.size())
108  this->paramError(
109  "targets",
110  "Number of target functions must equal the number of non-none constraint types. ",
111  fnames.size(),
112  " are provided, but ",
113  fcount,
114  " are used.");
115 }
std::map< std::pair< unsigned int, unsigned int >, std::pair< ConstraintType, const Function * > > ConstraintMap
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
static constexpr std::size_t dim
void addRequiredParam(const std::string &name, const std::string &doc_string)
Homogenization::ConstraintMap _cmap
Constraint map.
InputParameters validParams()
Interface for objects that use the homogenization constraint.
HomogenizationInterface(const InputParameters &parameters)
Real f(Real x)
Test function for Brents method.
static InputParameters validParams()
ConstraintType
Constraint type: stress/PK stress or strain/deformation gradient.
IntRange< T > make_range(T beg, T end)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
const MultiMooseEnum constraintType("strain stress none")
const Homogenization::ConstraintMap & cmap() const
Get the constraint map.
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)