Line data Source code
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 : 21 : /// Constraint type: stress/PK stress or strain/deformation gradient 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 : 33 : /** 34 : * Interface for objects that use the homogenization constraint 35 : */ 36 : template <class T> 37 : class HomogenizationInterface : public T 38 : { 39 : public: 40 : static InputParameters validParams(); 41 : 42 : HomogenizationInterface(const InputParameters & parameters); 43 : 44 : protected: 45 : /// Get the constraint map 46 : const Homogenization::ConstraintMap & cmap() const { return _cmap; } 47 : 48 : private: 49 : /// Constraint map 50 : Homogenization::ConstraintMap _cmap; 51 : }; 52 : 53 : template <class T> 54 : InputParameters 55 1464 : HomogenizationInterface<T>::validParams() 56 : { 57 1464 : InputParameters params = T::validParams(); 58 2928 : params.addRequiredParam<MultiMooseEnum>( 59 : "constraint_types", 60 : Homogenization::constraintType, 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 2928 : params.addRequiredParam<std::vector<FunctionName>>( 64 : "targets", "Functions giving the targets to hit for constraint types that are not none."); 65 1464 : return params; 66 0 : } 67 : 68 : template <class T> 69 898 : HomogenizationInterface<T>::HomogenizationInterface(const InputParameters & parameters) 70 898 : : T(parameters) 71 : { 72 : // Constraint types 73 898 : auto types = parameters.get<MultiMooseEnum>("constraint_types"); 74 898 : if (types.size() != Moose::dim * Moose::dim) 75 0 : this->paramError("constraint_types", 76 : "Number of constraint types must equal ", 77 : Moose::dim * Moose::dim, 78 : ", but ", 79 : types.size(), 80 : " are provided."); 81 : 82 : // Targets to hit 83 898 : const std::vector<FunctionName> & fnames = parameters.get<std::vector<FunctionName>>("targets"); 84 : 85 : // Prepare the constraint map 86 : unsigned int fcount = 0; 87 3592 : for (const auto j : make_range(Moose::dim)) 88 10776 : for (const auto i : make_range(Moose::dim)) 89 : { 90 8082 : const auto idx = i + Moose::dim * j; 91 8082 : const auto ctype = static_cast<Homogenization::ConstraintType>(types.get(idx)); 92 8082 : if (ctype != Homogenization::ConstraintType::None) 93 : { 94 5116 : if (fcount >= fnames.size()) 95 0 : 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 5116 : const Function * const f = &this->getFunctionByName(fnames[fcount++]); 102 5116 : _cmap[{i, j}] = {ctype, f}; 103 : } 104 : } 105 : 106 : // Make sure there aren't unused targets 107 898 : if (fcount != fnames.size()) 108 0 : 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 898 : }