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 
32 template <>
33 InputParameters
35 {
36  InputParameters params = validParams<C1ICBase>();
37  params.addClassDescription("Cross-shaped initial condition");
38  params.addParam<Real>("x1", 0.0, "The x coordinate of the lower left-hand corner of the box");
39  params.addParam<Real>("y1", 0.0, "The y coordinate of the lower left-hand corner of the box");
40  params.addParam<Real>("x2", 1.0, "The x coordinate of the upper right-hand corner of the box");
41  params.addParam<Real>("y2", 1.0, "The y coordinate of the upper right-hand corner of the box");
42  return params;
43 }
44 
45 CrossIC::CrossIC(const InputParameters & parameters)
46  : C1ICBase(parameters),
47  _x1(parameters.get<Real>("x1")),
48  _y1(parameters.get<Real>("y1")),
49  _x2(parameters.get<Real>("x2")),
50  _y2(parameters.get<Real>("y2"))
51 {
52 }
53 
54 Real
55 CrossIC::value(const Point & p)
56 {
57  const Real x = (p(0) - _x1) / (_x2 - _x1);
58  const Real y = (p(1) - _y1) / (_y2 - _y1);
59 
60  const Real cmax = _average + _amplitude;
61  const Real cmin = _average - _amplitude;
62 
63  if (x > (0.5 + _length / 2.0 + _buffer + _interface))
64  {
65  return cmin;
66  }
67  else if (x > 0.5 + _length / 2.0)
68  {
69  if (y > 0.5 + _width / 2.0 + _buffer + _interface)
70  {
71  return cmin;
72  }
73  else if (y > 0.5 + _width / 2.0)
74  {
75  Real xd = x - .5 - _length / 2.0;
76  Real yd = y - .5 - _width / 2.0;
77  Real r = std::sqrt(xd * xd + yd * yd);
78  return interfaceValue(r);
79  }
80  else if (y > 0.5 - _width / 2.0)
81  {
82  return interfaceValue(x - .5 - _length / 2.0);
83  }
84  else if (y > 0.5 - _width / 2. - _buffer - _interface)
85  {
86  Real xd = x - .5 - _length / 2.0;
87  Real yd = y - .5 + _width / 2.0;
88  Real r = std::sqrt(xd * xd + yd * yd);
89  return interfaceValue(r);
90  }
91  else
92  {
93  return cmin;
94  }
95  }
96  else if (x > 0.5 + _width / 2. + 2. * _buffer + _interface)
97  {
98  if (y > 0.5 + _width / 2 + _buffer + _interface)
99  return cmin;
100  else if (y > 0.5 + _width / 2.0)
101  return interfaceValue(y - .5 - _width / 2.0);
102  else if (y > 0.5 - _width / 2.0)
103  return cmax;
104  else if (y > 0.5 - _width / 2. - _buffer - _interface)
105  return interfaceValue(.5 - _width / 2. - y);
106  else
107  return cmin;
108  }
109  else if (x > 0.5 + _width / 2.0)
110  {
111  if (y > 0.5 + _length / 2. + _buffer + _interface)
112  {
113  return cmin;
114  }
115  else if (y > 0.5 + _length / 2.0)
116  {
117  Real xd = x - (.5 + _width / 2.0);
118  Real yd = y - (.5 + _length / 2.0);
119  Real r = std::sqrt(xd * xd + yd * yd);
120  return interfaceValue(r);
121  }
122  else if (y > 0.5 + _width / 2. + 2. * _buffer + _interface)
123  {
124  return interfaceValue(x - .5 - _width / 2.0);
125  }
126  else if (y > 0.5 + _width / 2.0)
127  {
128  Real xd = x - (.5 + _width / 2. + 2. * _buffer + _interface);
129  Real yd = y - (.5 + _width / 2. + 2. * _buffer + _interface);
130  Real r = std::sqrt(xd * xd + yd * yd);
131  return interfaceValue(2. * _buffer + _interface - r);
132  }
133  else if (y > 0.5 - _width / 2.0)
134  {
135  return cmax;
136  }
137  else if (y > 0.5 - _width / 2. - 2. * _buffer - _interface)
138  {
139  Real xd = x - (.5 + _width / 2. + 2. * _buffer + _interface);
140  Real yd = y - (.5 - _width / 2. - 2. * _buffer - _interface);
141  Real r = std::sqrt(xd * xd + yd * yd);
142  return interfaceValue(2. * _buffer + _interface - r);
143  }
144  else if (y > 0.5 - _length / 2.0)
145  {
146  return interfaceValue(x - .5 - _width / 2.0);
147  }
148  else if (y > 0.5 - _length / 2. - _buffer - _interface)
149  {
150  Real xd = x - (.5 + _width / 2.0);
151  Real yd = y - (.5 - _length / 2.0);
152  Real r = std::sqrt(xd * xd + yd * yd);
153  return interfaceValue(r);
154  }
155  else
156  {
157  return cmin;
158  }
159  }
160  else if (x > 0.5 - _width / 2.0)
161  {
162  if (y > 0.5 + _length / 2 + _buffer + _interface)
163  return cmin;
164  else if (y > 0.5 + _length / 2.0)
165  return interfaceValue(y - .5 - _length / 2.0);
166  else if (y > 0.5 - _length / 2.0)
167  return cmax;
168  else if (y > 0.5 - _length / 2. - _buffer - _interface)
169  return interfaceValue(.5 - _length / 2. - y);
170  else
171  return cmin;
172  }
173  else if (x > 0.5 - _width / 2. - 2. * _buffer - _interface)
174  {
175  if (y > 0.5 + _length / 2. + _buffer + _interface)
176  {
177  return cmin;
178  }
179  else if (y > 0.5 + _length / 2.0)
180  {
181  Real xd = x - (.5 - _width / 2.0);
182  Real yd = y - (.5 + _length / 2.0);
183  Real r = std::sqrt(xd * xd + yd * yd);
184  return interfaceValue(r);
185  }
186  else if (y > 0.5 + _width / 2. + 2. * _buffer + _interface)
187  {
188  return interfaceValue(.5 - _width / 2. - x);
189  }
190  else if (y > 0.5 + _width / 2.0)
191  {
192  Real xd = x - (.5 - _width / 2. - 2. * _buffer - _interface);
193  Real yd = y - (.5 + _width / 2. + 2. * _buffer + _interface);
194  Real r = std::sqrt(xd * xd + yd * yd);
195  return interfaceValue(2. * _buffer + _interface - r);
196  }
197  else if (y > 0.5 - _width / 2.0)
198  {
199  return cmax;
200  }
201  else if (y > 0.5 - _width / 2. - 2. * _buffer - _interface)
202  {
203  Real xd = x - (.5 - _width / 2. - 2. * _buffer - _interface);
204  Real yd = y - (.5 - _width / 2. - 2. * _buffer - _interface);
205  Real r = std::sqrt(xd * xd + yd * yd);
206  return interfaceValue(2. * _buffer + _interface - r);
207  }
208  else if (y > 0.5 - _length / 2.0)
209  {
210  return interfaceValue(.5 - _width / 2. - x);
211  }
212  else if (y > 0.5 - _length / 2. - _buffer - _interface)
213  {
214  Real xd = x - (.5 - _width / 2.0);
215  Real yd = y - (.5 - _length / 2.0);
216  Real r = std::sqrt(xd * xd + yd * yd);
217  return interfaceValue(r);
218  }
219  else
220  {
221  return cmin;
222  }
223  }
224  else if (x > 0.5 - _length / 2.0)
225  {
226  if (y > 0.5 + _width / 2 + _buffer + _interface)
227  return cmin;
228  else if (y > 0.5 + _width / 2.0)
229  return interfaceValue(y - .5 - _width / 2.0);
230  else if (y > 0.5 - _width / 2.0)
231  return cmax;
232  else if (y > 0.5 - _width / 2. - _buffer - _interface)
233  return interfaceValue(.5 - _width / 2. - y);
234  else
235  return cmin;
236  }
237  else if (x > (.5 - _length / 2. - _buffer - _interface))
238  {
239  if (y > 0.5 + _width / 2. + _buffer + _interface)
240  {
241  return cmin;
242  }
243  else if (y > 0.5 + _width / 2.0)
244  {
245  Real xd = x - (.5 - _length / 2.0);
246  Real yd = y - .5 - _width / 2.0;
247  Real r = std::sqrt(xd * xd + yd * yd);
248  return interfaceValue(r);
249  }
250  else if (y > 0.5 - _width / 2.0)
251  {
252  return interfaceValue(.5 - _length / 2. - x);
253  }
254  else if (y > 0.5 - _width / 2. - _buffer - _interface)
255  {
256  Real xd = x - (.5 - _length / 2.0);
257  Real yd = y - .5 + _width / 2.0;
258  Real r = std::sqrt(xd * xd + yd * yd);
259  return interfaceValue(r);
260  }
261  else
262  return cmin;
263  }
264  else
265  return cmin;
266 }
267 
269 CrossIC::gradient(const Point & p)
270 {
271  Point pxminus = p, pxplus = p, pyminus = p, pyplus = p;
272 
273  pxminus(0) -= TOLERANCE;
274  pyminus(1) -= TOLERANCE;
275  pxplus(0) += TOLERANCE;
276  pyplus(1) += TOLERANCE;
277 
278  Number uxminus = value(pxminus), uxplus = value(pxplus), uyminus = value(pyminus),
279  uyplus = value(pyplus);
280 
281  return Gradient((uxplus - uxminus) / 2.0 / TOLERANCE, (uyplus - uyminus) / 2.0 / TOLERANCE);
282 }
CrossIC::gradient
virtual RealGradient gradient(const Point &p)
Definition: CrossIC.C:269
libMesh::RealGradient
VectorValue< Real > RealGradient
Definition: GrainForceAndTorqueInterface.h:17
C1ICBase::_interface
Real _interface
Definition: C1ICBase.h:56
C1ICBase::_average
Real _average
Definition: C1ICBase.h:51
CrossIC
CrossIC creates a C1 continuous initial condition that looks like a cross in the middle of the domain...
Definition: CrossIC.h:43
registerMooseObject
registerMooseObject("PhaseFieldApp", CrossIC)
validParams< C1ICBase >
InputParameters validParams< C1ICBase >()
Definition: C1ICBase.C:32
validParams< CrossIC >
InputParameters validParams< CrossIC >()
Definition: CrossIC.C:34
C1ICBase::_amplitude
Real _amplitude
Definition: C1ICBase.h:52
CrossIC::_y2
const Real _y2
Definition: CrossIC.h:54
CrossIC::value
virtual Real value(const Point &p)
Definition: CrossIC.C:55
C1ICBase::_length
Real _length
Definition: C1ICBase.h:53
C1ICBase::_width
Real _width
Definition: C1ICBase.h:54
CrossIC::CrossIC
CrossIC(const InputParameters &parameters)
Definition: CrossIC.C:45
C1ICBase::interfaceValue
Number interfaceValue(Real r)
Definition: C1ICBase.C:58
C1ICBase::_buffer
Real _buffer
Definition: C1ICBase.h:55
CrossIC::_x1
const Real _x1
Definition: CrossIC.h:51
C1ICBase
C1ICBase is used by the CrossIC.
Definition: C1ICBase.h:45
CrossIC::_x2
const Real _x2
Definition: CrossIC.h:53
CrossIC::_y1
const Real _y1
Definition: CrossIC.h:52
CrossIC.h