Loading [MathJax]/extensions/tex2jax.js
www.mooseframework.org
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
ParsedSubdomainMeshGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
11 #include "Conversion.h"
12 #include "MooseMeshUtils.h"
13 #include "CastUniquePointer.h"
14 
15 #include "libmesh/fparser_ad.hh"
16 #include "libmesh/elem.h"
17 
19 
21 
24 {
27 
28  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
29  params.addRequiredParam<std::string>("combinatorial_geometry",
30  "Function expression encoding a combinatorial geometry");
31  params.addRequiredParam<subdomain_id_type>("block_id",
32  "Subdomain id to set for inside of the combinatorial");
33  params.addParam<SubdomainName>("block_name",
34  "Subdomain name to set for inside of the combinatorial");
35  params.addParam<std::vector<subdomain_id_type>>(
36  "excluded_subdomain_ids",
37  "A set of subdomain ids that will not changed even if "
38  "they are inside/outside the combinatorial geometry");
39  params.addParam<std::vector<std::string>>(
40  "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
41  params.addParam<std::vector<std::string>>(
42  "constant_expressions",
43  "Vector of values for the constants in constant_names (can be an FParser expression)");
44  params.addClassDescription("MeshModifier that uses a parsed expression (combinatorial_geometry) "
45  "to determine if an element (aka its centroid) is inside the "
46  "combinatorial geometry and "
47  "assigns a new block id.");
48 
49  return params;
50 }
51 
53  : MeshGenerator(parameters),
54  FunctionParserUtils(parameters),
55  _input(getMesh("input")),
56  _function(parameters.get<std::string>("combinatorial_geometry")),
57  _block_id(parameters.get<SubdomainID>("block_id")),
58  _excluded_ids(parameters.get<std::vector<SubdomainID>>("excluded_subdomain_ids"))
59 {
60  // base function object
61  _func_F = std::make_shared<ADFunction>();
62 
63  // set FParser internal feature flags
65 
66  // add the constant expressions
68  getParam<std::vector<std::string>>("constant_names"),
69  getParam<std::vector<std::string>>("constant_expressions"));
70 
71  // parse function
72  if (_func_F->Parse(_function, "x,y,z") >= 0)
73  mooseError("Invalid function\n",
74  _function,
75  "\nin ParsedSubdomainMeshModifier ",
76  name(),
77  ".\n",
78  _func_F->ErrorMsg());
79 
80  _func_params.resize(3);
81 }
82 
83 std::unique_ptr<MeshBase>
85 {
86  std::unique_ptr<MeshBase> mesh = std::move(_input);
87 
88  // Loop over the elements
89  for (const auto & elem : mesh->active_element_ptr_range())
90  {
91  _func_params[0] = elem->centroid()(0);
92  _func_params[1] = elem->centroid()(1);
93  _func_params[2] = elem->centroid()(2);
94  bool contains = evaluate(_func_F);
95 
96  if (contains && std::find(_excluded_ids.begin(), _excluded_ids.end(), elem->subdomain_id()) ==
97  _excluded_ids.end())
98  elem->subdomain_id() = _block_id;
99  }
100 
101  // Assign block name, if provided
102  if (isParamValid("block_name"))
103  mesh->subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
104 
105  return dynamic_pointer_cast<MeshBase>(mesh);
106 }
ParsedSubdomainMeshGenerator.h
defineLegacyParams
defineLegacyParams(ParsedSubdomainMeshGenerator)
MooseMeshUtils.h
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
MooseObject::isParamValid
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:100
ParsedSubdomainMeshGenerator::_function
const std::string _function
function expression
Definition: ParsedSubdomainMeshGenerator.h:37
MeshGenerator
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
registerMooseObject
registerMooseObject("MooseApp", ParsedSubdomainMeshGenerator)
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
FunctionParserUtils::_func_params
std::vector< Real > _func_params
Array to stage the parameters passed to the functions when calling Eval.
Definition: FunctionParserUtils.h:69
ParsedSubdomainMeshGenerator::ParsedSubdomainMeshGenerator
ParsedSubdomainMeshGenerator(const InputParameters &parameters)
Definition: ParsedSubdomainMeshGenerator.C:52
ParsedSubdomainMeshGenerator::_func_F
ADFunctionPtr _func_F
function parser object describing the combinatorial geometry
Definition: ParsedSubdomainMeshGenerator.h:46
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
FunctionParserUtils::addFParserConstants
void addFParserConstants(ADFunctionPtr &parser, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions)
add constants (which can be complex expressions) to the parser object
Definition: FunctionParserUtils.C:107
ParsedSubdomainMeshGenerator::validParams
static InputParameters validParams()
Definition: ParsedSubdomainMeshGenerator.C:23
ParsedSubdomainMeshGenerator::generate
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Definition: ParsedSubdomainMeshGenerator.C:84
ParsedSubdomainMeshGenerator::_input
std::unique_ptr< MeshBase > & _input
Definition: ParsedSubdomainMeshGenerator.h:34
FunctionParserUtils
Definition: FunctionParserUtils.h:29
InputParameters::addClassDescription
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Definition: InputParameters.C:70
FunctionParserUtils::validParams
static InputParameters validParams()
Definition: FunctionParserUtils.C:18
SubdomainID
subdomain_id_type SubdomainID
Definition: AutomaticMortarGeneration.h:48
ParsedSubdomainMeshGenerator::_block_id
const subdomain_id_type _block_id
Block ID to assign to the region.
Definition: ParsedSubdomainMeshGenerator.h:40
Conversion.h
std
Definition: TheWarehouse.h:80
MeshGenerator::validParams
static InputParameters validParams()
Constructor.
Definition: MeshGenerator.C:17
CastUniquePointer.h
ParsedSubdomainMeshGenerator::_excluded_ids
const std::vector< subdomain_id_type > _excluded_ids
A list of excluded subdomain ids that will not be changed even if they are in the combinatorial geome...
Definition: ParsedSubdomainMeshGenerator.h:43
FunctionParserUtils::evaluate
Real evaluate(ADFunctionPtr &)
Evaluate FParser object and check EvalError.
Definition: FunctionParserUtils.C:82
InputParameters::addRequiredParam
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
Definition: InputParameters.h:1176
ParsedSubdomainMeshGenerator
MeshGenerator for defining a Subdomain inside or outside of combinatorial geometry.
Definition: ParsedSubdomainMeshGenerator.h:24
MooseObject::name
virtual const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:70
FunctionParserUtils::setParserFeatureFlags
void setParserFeatureFlags(ADFunctionPtr &)
apply input paramters to internal feature flags of the parser object
Definition: FunctionParserUtils.C:75