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