www.mooseframework.org
DerivativeMaterialInterface.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 #ifndef DERIVATIVEMATERIALINTERFACE_H
15 #define DERIVATIVEMATERIALINTERFACE_H
16 
17 #include "AuxiliarySystem.h"
18 #include "BlockRestrictable.h"
19 #include "BoundaryRestrictable.h"
21 #include "KernelBase.h"
22 #include "Material.h"
23 #include "MaterialProperty.h"
24 #include "MooseVariable.h"
25 #include "NonlinearSystem.h"
26 
27 // Forward declarations
28 class FEProblemBase;
29 
34 template <class T>
36 {
37 public:
38  DerivativeMaterialInterface(const InputParameters & parameters);
39 
44  template <typename U>
45  const MaterialProperty<U> & getDefaultMaterialProperty(const std::string & name);
46 
48  template <typename U>
49  const MaterialProperty<U> & getDefaultMaterialPropertyByName(const std::string & name);
50 
52 
58  template <typename U>
59  MaterialProperty<U> & declarePropertyDerivative(const std::string & base,
60  const std::vector<VariableName> & c);
61  template <typename U>
62  MaterialProperty<U> & declarePropertyDerivative(const std::string & base,
63  const VariableName & c1,
64  const VariableName & c2 = "",
65  const VariableName & c3 = "");
67 
69 
75  template <typename U>
76  const MaterialProperty<U> & getMaterialPropertyDerivative(const std::string & base,
77  const std::vector<VariableName> & c);
78  template <typename U>
79  const MaterialProperty<U> & getMaterialPropertyDerivative(const std::string & base,
80  const VariableName & c1,
81  const VariableName & c2 = "",
82  const VariableName & c3 = "");
84 
86 
92  template <typename U>
93  const MaterialProperty<U> &
94  getMaterialPropertyDerivativeByName(const MaterialPropertyName & base,
95  const std::vector<VariableName> & c);
96  template <typename U>
97  const MaterialProperty<U> & getMaterialPropertyDerivativeByName(const MaterialPropertyName & base,
98  const VariableName & c1,
99  const VariableName & c2 = "",
100  const VariableName & c3 = "");
102 
104 
108  template <typename U>
109  void validateCoupling(const MaterialPropertyName & base,
110  const std::vector<VariableName> & c,
111  bool validate_aux = true);
112  template <typename U>
113  void validateCoupling(const MaterialPropertyName & base,
114  const VariableName & c1 = "",
115  const VariableName & c2 = "",
116  const VariableName & c3 = "");
117  template <typename U>
118  void validateNonlinearCoupling(const MaterialPropertyName & base,
119  const VariableName & c1 = "",
120  const VariableName & c2 = "",
121  const VariableName & c3 = "");
123 
130  template <typename U>
131  void validateDerivativeMaterialPropertyBase(const std::string & base);
132 
133 private:
135  template <typename U>
136  bool haveMaterialProperty(const std::string & prop_name);
137 
139  std::vector<VariableName>
140  buildVariableVector(const VariableName & c1, const VariableName & c2, const VariableName & c3);
141 
143  template <typename U>
144  void validateCouplingHelper(const MaterialPropertyName & base,
145  const std::vector<VariableName> & c,
146  const System & system,
147  std::vector<VariableName> & missing);
148 
149  // check if the speciified variable name is not the variable this kernel is acting on (always true
150  // for any other type of object)
151  bool isNotKernelVariable(const VariableName & name);
152 
155 };
156 
157 template <class T>
159  : T(parameters),
160  _dmi_fe_problem(*parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"))
161 {
162 }
163 
164 template <>
165 template <typename U>
166 bool
168 {
169  return (
170  (this->boundaryRestricted() && this->template hasBoundaryMaterialProperty<U>(prop_name)) ||
171  (this->template hasBlockMaterialProperty<U>(prop_name)));
172 }
173 
174 template <class T>
175 template <typename U>
176 bool
178 {
179  // Call the correct method to test for material property declarations
180  BlockRestrictable * blk = dynamic_cast<BlockRestrictable *>(this);
181  BoundaryRestrictable * bnd = dynamic_cast<BoundaryRestrictable *>(this);
182  return ((bnd && bnd->boundaryRestricted() &&
183  bnd->template hasBoundaryMaterialProperty<U>(prop_name)) ||
184  (blk && blk->template hasBlockMaterialProperty<U>(prop_name)) ||
185  (this->template hasMaterialProperty<U>(prop_name)));
186 }
187 
188 template <class T>
189 template <typename U>
190 const MaterialProperty<U> &
192 {
193  // get the base property name
194  std::string prop_name = this->deducePropertyName(name);
195 
196  // Check if it's just a constant
197  const MaterialProperty<U> * default_property =
198  this->template defaultMaterialProperty<U>(prop_name);
199  if (default_property)
200  return *default_property;
201 
202  // if found return the requested property
203  return getDefaultMaterialPropertyByName<U>(prop_name);
204 }
205 
206 template <class T>
207 template <typename U>
208 const MaterialProperty<U> &
210 {
211  // if found return the requested property
212  if (haveMaterialProperty<U>(prop_name))
213  return this->template getMaterialPropertyByName<U>(prop_name);
214 
215  return this->template getZeroMaterialProperty<U>(prop_name);
216 }
217 
218 template <class T>
219 template <typename U>
222  const std::vector<VariableName> & c)
223 {
224  return this->template declareProperty<U>(propertyName(base, c));
225 }
226 
227 template <class T>
228 template <typename U>
231  const VariableName & c1,
232  const VariableName & c2,
233  const VariableName & c3)
234 {
235  if (c3 != "")
236  return this->template declareProperty<U>(propertyNameThird(base, c1, c2, c3));
237  if (c2 != "")
238  return this->template declareProperty<U>(propertyNameSecond(base, c1, c2));
239  return this->template declareProperty<U>(propertyNameFirst(base, c1));
240 }
241 
242 template <class T>
243 template <typename U>
244 const MaterialProperty<U> &
246  const std::vector<VariableName> & c)
247 {
248  // get the base property name
249  std::string prop_name = this->deducePropertyName(base);
250 
255  if (this->template defaultMaterialProperty<U>(prop_name))
256  return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");
257 
258  return getDefaultMaterialPropertyByName<U>(propertyName(prop_name, c));
259 }
260 
261 template <class T>
262 template <typename U>
263 const MaterialProperty<U> &
265  const VariableName & c1,
266  const VariableName & c2,
267  const VariableName & c3)
268 {
269  // get the base property name
270  std::string prop_name = this->deducePropertyName(base);
271 
276  if (this->template defaultMaterialProperty<U>(prop_name))
277  return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");
278 
279  if (c3 != "")
280  return getDefaultMaterialPropertyByName<U>(propertyNameThird(prop_name, c1, c2, c3));
281  if (c2 != "")
282  return getDefaultMaterialPropertyByName<U>(propertyNameSecond(prop_name, c1, c2));
283  return getDefaultMaterialPropertyByName<U>(propertyNameFirst(prop_name, c1));
284 }
285 
286 template <class T>
287 template <typename U>
288 const MaterialProperty<U> &
290  const MaterialPropertyName & base, const std::vector<VariableName> & c)
291 {
292  return getDefaultMaterialPropertyByName<U>(propertyName(base, c));
293 }
294 
295 template <class T>
296 template <typename U>
297 const MaterialProperty<U> &
299  const MaterialPropertyName & base,
300  const VariableName & c1,
301  const VariableName & c2,
302  const VariableName & c3)
303 {
304  if (c3 != "")
305  return getDefaultMaterialPropertyByName<U>(propertyNameThird(base, c1, c2, c3));
306  if (c2 != "")
307  return getDefaultMaterialPropertyByName<U>(propertyNameSecond(base, c1, c2));
308  return getDefaultMaterialPropertyByName<U>(propertyNameFirst(base, c1));
309 }
310 
311 template <class T>
312 template <typename U>
313 void
315  const std::vector<VariableName> & c,
316  const System & system,
317  std::vector<VariableName> & missing)
318 {
319  unsigned int ncoupled = this->_coupled_moose_vars.size();
320 
321  // iterate over all variables in the current system (in groups)
322  for (unsigned int i = 0; i < system.n_variable_groups(); ++i)
323  {
324  const VariableGroup & vg = system.variable_group(i);
325  for (unsigned int j = 0; j < vg.n_variables(); ++j)
326  {
327  std::vector<VariableName> cj(c);
328  VariableName jname = vg.name(j);
329  cj.push_back(jname);
330 
331  // if the derivative exists make sure the variable is coupled
332  if (haveMaterialProperty<U>(propertyName(base, cj)))
333  {
334  // kernels to not have the variable they are acting on in coupled_moose_vars
335  bool is_missing = isNotKernelVariable(jname);
336 
337  for (unsigned int k = 0; k < ncoupled; ++k)
338  if (this->_coupled_moose_vars[k]->name() == jname)
339  {
340  is_missing = false;
341  break;
342  }
343 
344  if (is_missing)
345  missing.push_back(jname);
346  }
347  }
348  }
349 }
350 
351 template <class T>
352 template <typename U>
353 void
354 DerivativeMaterialInterface<T>::validateCoupling(const MaterialPropertyName & base,
355  const std::vector<VariableName> & c,
356  bool validate_aux)
357 {
358  // get the base property name
359  std::string prop_name = this->deducePropertyName(base);
360  // list of potentially missing coupled variables
361  std::vector<VariableName> missing;
362 
363  // iterate over all variables in the both the non-linear and auxiliary system (optional)
364  validateCouplingHelper<U>(
365  prop_name, c, _dmi_fe_problem.getNonlinearSystemBase().system(), missing);
366  if (validate_aux)
367  validateCouplingHelper<U>(prop_name, c, _dmi_fe_problem.getAuxiliarySystem().system(), missing);
368 
369  if (missing.size() > 0)
370  {
371  // join list of missing variable names
372  std::string list = missing[0];
373  for (unsigned int i = 1; i < missing.size(); ++i)
374  list += ", " + missing[i];
375 
376  mooseWarning("Missing coupled variables {",
377  list,
378  "} (add them to args parameter of ",
379  this->name(),
380  ")");
381  }
382 }
383 
384 template <class T>
385 std::vector<VariableName>
387  const VariableName & c2,
388  const VariableName & c3)
389 {
390  std::vector<VariableName> c;
391  if (c1 != "")
392  {
393  c.push_back(c1);
394  if (c2 != "")
395  {
396  c.push_back(c2);
397  if (c3 != "")
398  c.push_back(c3);
399  }
400  }
401  return c;
402 }
403 
404 template <class T>
405 template <typename U>
406 void
407 DerivativeMaterialInterface<T>::validateCoupling(const MaterialPropertyName & base,
408  const VariableName & c1,
409  const VariableName & c2,
410  const VariableName & c3)
411 {
412  validateCoupling<U>(base, buildVariableVector(c1, c2, c3), true);
413 }
414 
415 template <class T>
416 template <typename U>
417 void
419  const VariableName & c1,
420  const VariableName & c2,
421  const VariableName & c3)
422 {
423  validateCoupling<U>(base, buildVariableVector(c1, c2, c3), false);
424 }
425 
426 template <class T>
427 template <typename U>
428 void
430 {
431  // resolve the input parameter name base to the actual material property name
432  const MaterialPropertyName prop_name = this->template getParam<MaterialPropertyName>(base);
433 
434  // check if the material property does not exist on the blocks of the current object,
435  // and check if it is not a plain number in the input file
436  if (!haveMaterialProperty<U>(prop_name) &&
437  this->template defaultMaterialProperty<U>(prop_name) == 0)
438  mooseWarning("The material property '",
439  prop_name,
440  "' does not exist. The kernel '",
441  this->name(),
442  "' only needs its derivatives, but this may indicate a typo in the input file.");
443 }
444 
445 template <class T>
446 inline bool
448 {
449  // try to cast this to a Kernel pointer
450  KernelBase * k = dynamic_cast<KernelBase *>(this);
451 
452  // This interface is not templated on a class derived from Kernel
453  if (k == NULL)
454  return true;
455 
456  // We are templated on a kernel class, so we check if the kernel variable
457  return k->variable().name() != name;
458 }
459 
460 #endif // DERIVATIVEMATERIALINTERFACE_H
DerivativeMaterialInterface(const InputParameters &parameters)
std::vector< VariableName > buildVariableVector(const VariableName &c1, const VariableName &c2, const VariableName &c3)
helper method to combine multiple VariableNames into a vector (if they are != "") ...
NonlinearSystemBase & getNonlinearSystemBase()
void validateCoupling(const MaterialPropertyName &base, const std::vector< VariableName > &c, bool validate_aux=true)
check if derivatives of the passed in material property exist w.r.t a variable that is not coupled in...
const MaterialProperty< U > & getMaterialPropertyDerivative(const std::string &base, const std::vector< VariableName > &c)
Methods for retreiving derivative material properties.
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
const MaterialProperty< U > & getDefaultMaterialPropertyByName(const std::string &name)
Fetch a material property by name if it exists, otherwise return getZeroMaterialProperty.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const MaterialPropertyName propertyNameSecond(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2) const
Helper functions to generate the material property names for the second derivatives.
const std::string & name() const
Get the variable name.
const MaterialPropertyName propertyNameThird(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2, const VariableName &c3) const
Helper functions to generate the material property names for the third derivatives.
nl system()
This is the common base class for the two main kernel types implemented in MOOSE, EigenKernel and Ker...
Definition: KernelBase.h:47
void validateNonlinearCoupling(const MaterialPropertyName &base, const VariableName &c1="", const VariableName &c2="", const VariableName &c3="")
bool isNotKernelVariable(const VariableName &name)
FEProblemBase & _dmi_fe_problem
Reference to FEProblemBase.
AuxiliarySystem & getAuxiliarySystem()
void validateDerivativeMaterialPropertyBase(const std::string &base)
Check if the material property base exists.
bool haveMaterialProperty(const std::string &prop_name)
Check if a material property is present with the applicable restrictions.
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.
Interface class ("Veneer") to provide generator methods for derivative material property names...
virtual System & system() override
Get the reference to the libMesh system.
virtual System & system() override
Get the reference to the libMesh system.
const MaterialPropertyName propertyNameFirst(const MaterialPropertyName &base, const VariableName &c1) const
Helper functions to generate the material property names for the first derivatives.
Concrete definition of a parameter value for a specified type.
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
const MaterialProperty< U > & getMaterialPropertyDerivativeByName(const MaterialPropertyName &base, const std::vector< VariableName > &c)
Methods for retreiving derivative material properties.
MooseVariable & variable()
Returns the variable number that this Kernel operates on.
Definition: KernelBase.C:156
void validateCouplingHelper(const MaterialPropertyName &base, const std::vector< VariableName > &c, const System &system, std::vector< VariableName > &missing)
helper method to compile list of missing coupled variables for a given system
const MaterialProperty< U > & getDefaultMaterialProperty(const std::string &name)
Fetch a material property if it exists, otherwise return getZeroMaterialProperty. ...
MaterialProperty< U > & declarePropertyDerivative(const std::string &base, const std::vector< VariableName > &c)
Methods for declaring derivative material properties.
void mooseWarning(Args &&...args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:194