https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MultiBoundingBoxIC.C
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#include "MultiBoundingBoxIC.h"
11#include "MooseMesh.h"
12#include "FEProblemBase.h"
13
15
16namespace
17{
18// Convenience function for sizing a vector to "n" given a vector with size 1 or "n"
19std::vector<Real>
20sizeVector(std::vector<Real> v, std::size_t size)
21{
22 if (v.size() == 1)
23 return std::vector<Real>(size, v[0]);
24 else
25 return v;
26}
27}
28
31{
33 params.addClassDescription("Specify variable values inside and outside a list of box shaped "
34 "axis-aligned regions defined by pairs of opposing corners");
35 params.addRequiredParam<std::vector<Point>>("corners", "The corner coordinates boxes");
36 params.addRequiredParam<std::vector<Point>>(
37 "opposite_corners", "The coordinates of the opposite corners of the boxes");
38 params.addRequiredParam<std::vector<Real>>("inside",
39 "The value of the variable inside each box "
40 "(one value per box or a single value for "
41 "all boxes)");
42 params.addParam<Real>("outside", 0.0, "The value of the variable outside the box");
43
44 params.addClassDescription("Allows setting the initial condition of a value of a field inside "
45 "and outside multiple bounding boxes.");
46 return params;
47}
48
50 : InitialCondition(parameters),
51 _c1(getParam<std::vector<Point>>("corners")),
52 _c2(getParam<std::vector<Point>>("opposite_corners")),
53 _nbox(_c1.size()),
54 _dim(_fe_problem.mesh().dimension()),
55 _inside(sizeVector(getParam<std::vector<Real>>("inside"), _nbox)),
56 _outside(getParam<Real>("outside"))
57{
58 // make sure inputs are the same length
59 if (_c2.size() != _nbox || _inside.size() != _nbox)
60 mooseError("vector inputs must all be the same size");
61}
62
63Real
65{
66 Real value = _outside;
67
68 for (unsigned int b = 0; b < _nbox; ++b)
69 {
70 if ((_c1[b](0) < _c2[b](0) && p(0) >= _c1[b](0) && p(0) <= _c2[b](0)) ||
71 (_c1[b](0) >= _c2[b](0) && p(0) <= _c1[b](0) && p(0) >= _c2[b](0)))
72 if (_dim <= 1 || (_c1[b](1) < _c2[b](1) && p(1) >= _c1[b](1) && p(1) <= _c2[b](1)) ||
73 (_c1[b](1) >= _c2[b](1) && p(1) <= _c1[b](1) && p(1) >= _c2[b](1)))
74 if (_dim <= 2 || (_c1[b](2) < _c2[b](2) && p(2) >= _c1[b](2) && p(2) <= _c2[b](2)) ||
75 (_c1[b](2) >= _c2[b](2) && p(2) <= _c1[b](2) && p(2) >= _c2[b](2)))
76 {
77 value = _inside[b];
78 break;
79 }
80 }
81
82 return value;
83}
const Real p
const double v
registerMooseObject("PhaseFieldApp", MultiBoundingBoxIC)
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void mooseError(Args &&... args) const
MultiBoundingBoxIC allows setting the initial condition of a value of a field inside and outside mult...
const std::vector< Point > _c2
const std::vector< Point > _c1
lists of opposite corners
virtual Real value(const Point &p) override
const unsigned int _nbox
number of boxes
const Real _outside
values outside the boxes
static InputParameters validParams()
const std::vector< Real > _inside
values inside the boxes
MultiBoundingBoxIC(const InputParameters &parameters)
const unsigned int _dim
dimensionality of the mesh
MeshBase & mesh