www.mooseframework.org
CrossIC.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 
10 #include "CrossIC.h"
11 
12 // Portions of this code Copyright 2007-2009 Roy Stogner
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 //"Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 
30 registerMooseObject("PhaseFieldApp", CrossIC);
31 
34 {
36  params.addClassDescription("Cross-shaped initial condition");
37  params.addParam<Real>("x1", 0.0, "The x coordinate of the lower left-hand corner of the box");
38  params.addParam<Real>("y1", 0.0, "The y coordinate of the lower left-hand corner of the box");
39  params.addParam<Real>("x2", 1.0, "The x coordinate of the upper right-hand corner of the box");
40  params.addParam<Real>("y2", 1.0, "The y coordinate of the upper right-hand corner of the box");
41  return params;
42 }
43 
44 CrossIC::CrossIC(const InputParameters & parameters)
45  : C1ICBase(parameters),
46  _x1(parameters.get<Real>("x1")),
47  _y1(parameters.get<Real>("y1")),
48  _x2(parameters.get<Real>("x2")),
49  _y2(parameters.get<Real>("y2"))
50 {
51 }
52 
53 Real
54 CrossIC::value(const Point & p)
55 {
56  const Real x = (p(0) - _x1) / (_x2 - _x1);
57  const Real y = (p(1) - _y1) / (_y2 - _y1);
58 
59  const Real cmax = _average + _amplitude;
60  const Real cmin = _average - _amplitude;
61 
62  if (x > (0.5 + _length / 2.0 + _buffer + _interface))
63  {
64  return cmin;
65  }
66  else if (x > 0.5 + _length / 2.0)
67  {
68  if (y > 0.5 + _width / 2.0 + _buffer + _interface)
69  {
70  return cmin;
71  }
72  else if (y > 0.5 + _width / 2.0)
73  {
74  Real xd = x - .5 - _length / 2.0;
75  Real yd = y - .5 - _width / 2.0;
76  Real r = std::sqrt(xd * xd + yd * yd);
77  return interfaceValue(r);
78  }
79  else if (y > 0.5 - _width / 2.0)
80  {
81  return interfaceValue(x - .5 - _length / 2.0);
82  }
83  else if (y > 0.5 - _width / 2. - _buffer - _interface)
84  {
85  Real xd = x - .5 - _length / 2.0;
86  Real yd = y - .5 + _width / 2.0;
87  Real r = std::sqrt(xd * xd + yd * yd);
88  return interfaceValue(r);
89  }
90  else
91  {
92  return cmin;
93  }
94  }
95  else if (x > 0.5 + _width / 2. + 2. * _buffer + _interface)
96  {
97  if (y > 0.5 + _width / 2 + _buffer + _interface)
98  return cmin;
99  else if (y > 0.5 + _width / 2.0)
100  return interfaceValue(y - .5 - _width / 2.0);
101  else if (y > 0.5 - _width / 2.0)
102  return cmax;
103  else if (y > 0.5 - _width / 2. - _buffer - _interface)
104  return interfaceValue(.5 - _width / 2. - y);
105  else
106  return cmin;
107  }
108  else if (x > 0.5 + _width / 2.0)
109  {
110  if (y > 0.5 + _length / 2. + _buffer + _interface)
111  {
112  return cmin;
113  }
114  else if (y > 0.5 + _length / 2.0)
115  {
116  Real xd = x - (.5 + _width / 2.0);
117  Real yd = y - (.5 + _length / 2.0);
118  Real r = std::sqrt(xd * xd + yd * yd);
119  return interfaceValue(r);
120  }
121  else if (y > 0.5 + _width / 2. + 2. * _buffer + _interface)
122  {
123  return interfaceValue(x - .5 - _width / 2.0);
124  }
125  else if (y > 0.5 + _width / 2.0)
126  {
127  Real xd = x - (.5 + _width / 2. + 2. * _buffer + _interface);
128  Real yd = y - (.5 + _width / 2. + 2. * _buffer + _interface);
129  Real r = std::sqrt(xd * xd + yd * yd);
130  return interfaceValue(2. * _buffer + _interface - r);
131  }
132  else if (y > 0.5 - _width / 2.0)
133  {
134  return cmax;
135  }
136  else if (y > 0.5 - _width / 2. - 2. * _buffer - _interface)
137  {
138  Real xd = x - (.5 + _width / 2. + 2. * _buffer + _interface);
139  Real yd = y - (.5 - _width / 2. - 2. * _buffer - _interface);
140  Real r = std::sqrt(xd * xd + yd * yd);
141  return interfaceValue(2. * _buffer + _interface - r);
142  }
143  else if (y > 0.5 - _length / 2.0)
144  {
145  return interfaceValue(x - .5 - _width / 2.0);
146  }
147  else if (y > 0.5 - _length / 2. - _buffer - _interface)
148  {
149  Real xd = x - (.5 + _width / 2.0);
150  Real yd = y - (.5 - _length / 2.0);
151  Real r = std::sqrt(xd * xd + yd * yd);
152  return interfaceValue(r);
153  }
154  else
155  {
156  return cmin;
157  }
158  }
159  else if (x > 0.5 - _width / 2.0)
160  {
161  if (y > 0.5 + _length / 2 + _buffer + _interface)
162  return cmin;
163  else if (y > 0.5 + _length / 2.0)
164  return interfaceValue(y - .5 - _length / 2.0);
165  else if (y > 0.5 - _length / 2.0)
166  return cmax;
167  else if (y > 0.5 - _length / 2. - _buffer - _interface)
168  return interfaceValue(.5 - _length / 2. - y);
169  else
170  return cmin;
171  }
172  else if (x > 0.5 - _width / 2. - 2. * _buffer - _interface)
173  {
174  if (y > 0.5 + _length / 2. + _buffer + _interface)
175  {
176  return cmin;
177  }
178  else if (y > 0.5 + _length / 2.0)
179  {
180  Real xd = x - (.5 - _width / 2.0);
181  Real yd = y - (.5 + _length / 2.0);
182  Real r = std::sqrt(xd * xd + yd * yd);
183  return interfaceValue(r);
184  }
185  else if (y > 0.5 + _width / 2. + 2. * _buffer + _interface)
186  {
187  return interfaceValue(.5 - _width / 2. - x);
188  }
189  else if (y > 0.5 + _width / 2.0)
190  {
191  Real xd = x - (.5 - _width / 2. - 2. * _buffer - _interface);
192  Real yd = y - (.5 + _width / 2. + 2. * _buffer + _interface);
193  Real r = std::sqrt(xd * xd + yd * yd);
194  return interfaceValue(2. * _buffer + _interface - r);
195  }
196  else if (y > 0.5 - _width / 2.0)
197  {
198  return cmax;
199  }
200  else if (y > 0.5 - _width / 2. - 2. * _buffer - _interface)
201  {
202  Real xd = x - (.5 - _width / 2. - 2. * _buffer - _interface);
203  Real yd = y - (.5 - _width / 2. - 2. * _buffer - _interface);
204  Real r = std::sqrt(xd * xd + yd * yd);
205  return interfaceValue(2. * _buffer + _interface - r);
206  }
207  else if (y > 0.5 - _length / 2.0)
208  {
209  return interfaceValue(.5 - _width / 2. - x);
210  }
211  else if (y > 0.5 - _length / 2. - _buffer - _interface)
212  {
213  Real xd = x - (.5 - _width / 2.0);
214  Real yd = y - (.5 - _length / 2.0);
215  Real r = std::sqrt(xd * xd + yd * yd);
216  return interfaceValue(r);
217  }
218  else
219  {
220  return cmin;
221  }
222  }
223  else if (x > 0.5 - _length / 2.0)
224  {
225  if (y > 0.5 + _width / 2 + _buffer + _interface)
226  return cmin;
227  else if (y > 0.5 + _width / 2.0)
228  return interfaceValue(y - .5 - _width / 2.0);
229  else if (y > 0.5 - _width / 2.0)
230  return cmax;
231  else if (y > 0.5 - _width / 2. - _buffer - _interface)
232  return interfaceValue(.5 - _width / 2. - y);
233  else
234  return cmin;
235  }
236  else if (x > (.5 - _length / 2. - _buffer - _interface))
237  {
238  if (y > 0.5 + _width / 2. + _buffer + _interface)
239  {
240  return cmin;
241  }
242  else if (y > 0.5 + _width / 2.0)
243  {
244  Real xd = x - (.5 - _length / 2.0);
245  Real yd = y - .5 - _width / 2.0;
246  Real r = std::sqrt(xd * xd + yd * yd);
247  return interfaceValue(r);
248  }
249  else if (y > 0.5 - _width / 2.0)
250  {
251  return interfaceValue(.5 - _length / 2. - x);
252  }
253  else if (y > 0.5 - _width / 2. - _buffer - _interface)
254  {
255  Real xd = x - (.5 - _length / 2.0);
256  Real yd = y - .5 + _width / 2.0;
257  Real r = std::sqrt(xd * xd + yd * yd);
258  return interfaceValue(r);
259  }
260  else
261  return cmin;
262  }
263  else
264  return cmin;
265 }
266 
268 CrossIC::gradient(const Point & p)
269 {
270  Point pxminus = p, pxplus = p, pyminus = p, pyplus = p;
271 
272  pxminus(0) -= TOLERANCE;
273  pyminus(1) -= TOLERANCE;
274  pxplus(0) += TOLERANCE;
275  pyplus(1) += TOLERANCE;
276 
277  Number uxminus = value(pxminus), uxplus = value(pxplus), uyminus = value(pyminus),
278  uyplus = value(pyplus);
279 
280  return Gradient((uxplus - uxminus) / 2.0 / TOLERANCE, (uyplus - uyminus) / 2.0 / TOLERANCE);
281 }
const Real _x2
Definition: CrossIC.h:49
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
Real _interface
Definition: C1ICBase.h:52
static InputParameters validParams()
Definition: C1ICBase.C:31
const std::vector< double > y
Real _average
Definition: C1ICBase.h:47
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Real _length
Definition: C1ICBase.h:49
C1ICBase is used by the CrossIC.
Definition: C1ICBase.h:39
Real _amplitude
Definition: C1ICBase.h:48
registerMooseObject("PhaseFieldApp", CrossIC)
Number interfaceValue(Real r)
Definition: C1ICBase.C:57
CrossIC creates a C1 continuous initial condition that looks like a cross in the middle of the domain...
Definition: CrossIC.h:37
CrossIC(const InputParameters &parameters)
Definition: CrossIC.C:44
const Real _y1
Definition: CrossIC.h:48
const Real _x1
Definition: CrossIC.h:47
const std::vector< double > x
const Real _y2
Definition: CrossIC.h:50
virtual Real value(const Point &p)
Definition: CrossIC.C:54
NumberVectorValue Gradient
static InputParameters validParams()
Definition: CrossIC.C:33
virtual RealGradient gradient(const Point &p)
Definition: CrossIC.C:268
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _width
Definition: C1ICBase.h:50
void addClassDescription(const std::string &doc_string)
Real Number
Real _buffer
Definition: C1ICBase.h:51
const Elem & get(const ElemType type_in)