https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
17{
18// Moose constraint type, for input
19const MultiMooseEnum constraintType("strain stress none");
20
23{
24 Strain,
25 Stress,
26 None
27};
28
30 std::map<std::pair<unsigned int, unsigned int>, std::pair<ConstraintType, const Function *>>;
31}
32
36template <class T>
38{
39public:
41
43
44protected:
46 const Homogenization::ConstraintMap & cmap() const { return _cmap; }
47
48private:
51};
52
53template <class T>
56{
57 InputParameters params = T::validParams();
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
68template <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}
Real f(Real x)
Test function for Brents method.
const double T
Interface for objects that use the homogenization constraint.
HomogenizationInterface(const InputParameters &parameters)
static InputParameters validParams()
Homogenization::ConstraintMap _cmap
Constraint map.
const Homogenization::ConstraintMap & cmap() const
Get the constraint map.
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const MultiMooseEnum constraintType("strain stress none")
std::map< std::pair< unsigned int, unsigned int >, std::pair< ConstraintType, const Function * > > ConstraintMap
ConstraintType
Constraint type: stress/PK stress or strain/deformation gradient.
static constexpr std::size_t dim