24 const real_t xc = x(0) - 0.0, yc = x(1) - 0.5,
25 zc = (x.
Size() == 3) ? x(2) - 0.5 : 0.0;
26 const real_t r = sqrt(xc*xc + yc*yc + zc*zc);
28 real_t val = 0.5*(1+std::tanh(sf*(r-r1))) - 0.5*(1+std::tanh(sf*(r-r2)));
30 val = std::max((
real_t) 0.,val);
31 val = std::min((
real_t) 1.,val);
38 real_t xc = x(0) - 0.75, yc = x(1) - 0.75,
39 zc = (x.
Size() == 3) ? x(2) - 0.0 : 0.0;
40 real_t r = sqrt(xc*xc + yc*yc + zc*zc);
42 real_t val = 0.5*(1+std::tanh(sf*(r-r1))) - 0.5*(1+std::tanh(sf*(r-r2)));
43 val = std::max((
real_t) 0.,val);
44 val = std::min((
real_t) 1.,val);
47 xc = x(0) - 0.75; yc = x(1) + 1.25;
48 zc = (x.
Size() == 3) ? x(2) - 0.0 : 0.0;
49 r = sqrt(xc*xc + yc*yc + zc*zc);
50 r1 = 0.45; r2 = 0.55; sf=30.0;
51 real_t val1 = 0.5*(1+std::tanh(sf*(r-r1))) - 0.5*(1+std::tanh(sf*(r-r2)));
52 val = std::max(val, val1);
55 xc = x(0) + 1.25; yc = x(1) - 0.75;
56 zc = (x.
Size() == 3) ? x(2) - 0.0 : 0.0;
57 r = sqrt(xc*xc + yc*yc + zc*zc);
58 r1 = 0.45; r2 = 0.55; sf=30.0;
59 real_t val2 = 0.5*(1+std::tanh(sf*(r-r1))) - 0.5*(1+std::tanh(sf*(r-r2)));
60 val = std::max(val, val2);
63 xc = x(0) + 1.25; yc = x(1) + 1.25;
64 zc = (x.
Size() == 3) ? x(2) - 0.0 : 0.0;
65 r = sqrt(xc*xc + yc*yc + zc*zc);
66 r1 = 0.45; r2 = 0.55; sf=30.0;
67 real_t val3 = 0.5*(1+std::tanh(sf*(r-r1))) - 0.5*(1+std::tanh(sf*(r-r2)));
68 val = std::max(val, val3);
76 const int NE = mesh.
GetNE();
78 mass = 0.0, vol = 0.0;
79 for (
int e = 0; e < NE; e++)
125 real_t volume_ind, volume;
128 int NE = mesh.
GetNE();
137 const real_t small_el_size = volume_ind / NE +
138 (volume - volume_ind) / (size_ratio * NE);
139 const real_t big_el_size = size_ratio * small_el_size;
140 for (
int i = 0; i < size.
Size(); i++)
142 size(i) = size(i) * small_el_size + (1.0 - size(i)) * big_el_size;
148 real_t xc = x(0)-0.5, yc = x(1)-0.5;
149 real_t th = 22.5*M_PI/180.;
150 real_t xn = cos(th)*xc + sin(th)*yc;
151 real_t yn = -sin(th)*xc + cos(th)*yc;
152 real_t th2 = (th > 45.*M_PI/180) ? M_PI/2 - th : th;
153 real_t stretch = 1/cos(th2);
154 xc = xn/stretch; yc = yn/stretch;
158 real_t wgt = std::tanh((tfac*(yc) + s2*std::sin(s1*M_PI*xc)) + 1);
159 if (wgt > 1) { wgt = 1; }
160 if (wgt < 0) { wgt = 0; }
166 return M_PI * x(1) * (1.0 - x(1)) * cos(2 * M_PI * x(0));
177 v[0] = l1/pow(l2*l3,0.5);
178 v[1] = l2/pow(l1*l3,0.5);
179 v[2] = l3/pow(l2*l1,0.5);
196 if (metric != 14 && metric != 36 && metric != 85)
198 const real_t xc = pos(0) - 0.5, yc = pos(1) - 0.5;
199 const real_t r = sqrt(xc*xc + yc*yc);
203 const real_t tan1 = std::tanh(sf*(r-r1)),
204 tan2 = std::tanh(sf*(r-r2));
206 K(0, 0) = eps + 1.0 * (tan1 - tan2);
211 else if (metric == 14 || metric == 36)
213 const real_t xc = pos(0), yc = pos(1);
214 real_t theta = M_PI * yc * (1.0 - yc) * cos(2 * M_PI * xc);
217 K(0, 0) = cos(theta);
218 K(1, 0) = sin(theta);
219 K(0, 1) = -sin(theta);
220 K(1, 1) = cos(theta);
224 else if (metric == 85)
227 real_t xc = x(0)-0.5, yc = x(1)-0.5;
228 real_t th = 22.5*M_PI/180.;
229 real_t xn = cos(th)*xc + sin(th)*yc;
230 real_t yn = -sin(th)*xc + cos(th)*yc;
236 real_t wgt = std::tanh((tfac*(yc) + s2*std::sin(s1*M_PI*xc)) + 1)
237 - std::tanh((tfac*(yc) + s2*std::sin(s1*M_PI*xc)) - 1);
238 if (wgt > 1) { wgt = 1; }
239 if (wgt < 0) { wgt = 0; }
241 xc = pos(0), yc = pos(1);
242 real_t theta = M_PI * (yc) * (1.0 - yc) * cos(2 * M_PI * xc);
244 K(0, 0) = cos(theta);
245 K(1, 0) = sin(theta);
246 K(0, 1) = -sin(theta);
247 K(1, 1) = cos(theta);
249 real_t asp_ratio_tar = 0.1 + 1*(1-wgt)*(1-wgt);
251 K(0, 0) *= 1/pow(asp_ratio_tar,0.5);
252 K(1, 0) *= 1/pow(asp_ratio_tar,0.5);
253 K(0, 1) *= pow(asp_ratio_tar,0.5);
254 K(1, 1) *= pow(asp_ratio_tar,0.5);
264 if (metric != 14 && metric != 85)
266 const real_t xc = pos(0) - 0.5, yc = pos(1) - 0.5;
267 const real_t r = sqrt(xc*xc + yc*yc);
270 const real_t tan1 = std::tanh(sf*(r-r1)),
271 tan2 = std::tanh(sf*(r-r2));
272 real_t tan1d = 0., tan2d = 0.;
275 tan1d = (1.-tan1*tan1)*(sf)/r,
276 tan2d = (1.-tan2*tan2)*(sf)/r;
282 if (comp == 0) { K(0, 0) = tan1d*xc - tan2d*xc; }
283 else if (comp == 1) { K(0, 0) = tan1d*yc - tan2d*yc; }
300 hr_target_type(hr_target_type_) { }
307 if (hr_target_type == 0)
309 real_t small = 0.001, big = 0.01;
310 if (
dim == 3) { small = 0.005, big = 0.1; }
311 const real_t xc = pos(0) - 0.5, yc = pos(1) - 0.5;
315 r = sqrt(xc*xc + yc*yc);
319 const real_t zc = pos(2) - 0.5;
320 r = sqrt(xc*xc + yc*yc + zc*zc);
324 const real_t tan1 = std::tanh(sf*(r-r1)),
325 tan2 = std::tanh(sf*(r-r2));
327 real_t ind = (tan1 - tan2);
328 if (ind > 1.0) {ind = 1.;}
329 if (ind < 0.0) {ind = 0.;}
330 real_t val = ind * small + (1.0 - ind) * big;
336 K(0, 0) *= pow(val,0.5);
337 K(1, 1) *= pow(val,0.5);
338 if (
dim == 3) { K(2, 2) = pow(val,0.5); }
340 else if (hr_target_type == 1)
342 const real_t small = 0.001, big = 0.01;
343 const real_t xc = pos(0)-0.5, yc = pos(1)-0.5;
344 const real_t rv = xc*xc + yc*yc;
346 if (rv>0.) {r = sqrt(rv);}
351 const real_t eps2 = szfac/asfac;
352 const real_t eps1 = szfac;
354 real_t tan1 = std::tanh(sf*(r-r1)+1),
355 tan2 = std::tanh(sf*(r-r2)-1);
356 real_t wgt = 0.5*(tan1-tan2);
358 tan1 = std::tanh(sf*(r-r1)),
359 tan2 = std::tanh(sf*(r-r2));
361 real_t ind = (tan1 - tan2);
362 if (ind > 1.0) {ind = 1.;}
363 if (ind < 0.0) {ind = 0.;}
364 real_t szval = ind * small + (1.0 - ind) * big;
366 real_t th = std::atan2(yc,xc)*180./M_PI;
367 if (wgt > 1) { wgt = 1; }
368 if (wgt < 0) { wgt = 0; }
370 real_t maxval = eps2 + eps1*(1-wgt)*(1-wgt);
372 real_t avgval = 0.5*(maxval+minval);
373 real_t ampval = 0.5*(maxval-minval);
374 real_t val1 = avgval + ampval*sin(2.*th*M_PI/180.+90*M_PI/180.);
375 real_t val2 = avgval + ampval*sin(2.*th*M_PI/180.-90*M_PI/180.);
382 K(0,0) *= pow(szval,0.5);
383 K(1,1) *= pow(szval,0.5);
385 else if (hr_target_type == 2)
387 real_t xc = pos(0)-0.5, yc = pos(1)-0.5;
388 real_t th = 15.5*M_PI/180.;
389 real_t xn = cos(th)*xc + sin(th)*yc;
390 real_t yn = -sin(th)*xc + cos(th)*yc;
391 real_t th2 = (th > 45.*M_PI/180) ? M_PI/2 - th : th;
392 real_t stretch = 1/cos(th2);
400 real_t wgt = std::tanh((tfac*(yc-yl1) + s2*std::sin(s1*M_PI*xc)) + 1) -
401 std::tanh((tfac*(yc-yl2) + s2*std::sin(s1*M_PI*xc)) - 1);
402 if (wgt > 1) { wgt = 1; }
403 if (wgt < 0) { wgt = 0; }
407 K(1,1) = eps1/eps2 + eps1*(1-wgt)*(1-wgt);
412 else { MFEM_ABORT(
"Unsupported option / wrong input."); }
429 const real_t r = sqrt(x(0)*x(0) + x(1)*x(1) + 1e-12);
431 real_t l2 = 0.2 + 0.5*std::tanh((r-0.16)/den) - 0.5*std::tanh((r-0.17)/den)
432 + 0.5*std::tanh((r-0.23)/den) - 0.5*std::tanh((r-0.24)/den);
439 const real_t xc = x(0) - 0.1, yc = x(1) - 0.2;
440 const real_t r = sqrt(xc*xc + yc*yc);
442 real_t val = 0.5*(1+std::tanh(sf*(r-r1))) - 0.5*(1+std::tanh(sf*(r-r2)));
444 val = std::max((
real_t) 0.,val);
445 val = std::min((
real_t) 1.,val);
457 const real_t sine = 0.25 * std::sin(4 * M_PI * x(0));
458 return (x(1) >= sine + 0.5) ? 1.0 : -1.0;
464 const real_t xc = x(0) - 0.5, yc = x(1) - 0.5;
465 const real_t r = sqrt(xc*xc + yc*yc);
470 const real_t xc = x(0) - 0.5, yc = x(1) - 0.5, zc = x(2) - 0.5;
471 const real_t r = sqrt(xc*xc + yc*yc + zc*zc);
497 return (integral > 0.0) ? 1.0 : 0.0;
499 else if (approach == 1)
502 return minval > 0.0 ? 1.0 : 0.0;
545 S->
Mult(tmp, fieldtrue);
void EvalGrad(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip, int comp) override
Evaluate the derivative of the matrix coefficient with respect to comp in the element described by T ...
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
HRHessianCoefficient(int dim_, int hr_target_type_=0)
void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
HessianCoefficient(int dim, int metric_id)
void EvalGrad(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip, int comp) override
Evaluate the derivative of the matrix coefficient with respect to comp in the element described by T ...
Data type for scaled Jacobi-type smoother of sparse matrix.
void Mult(const Vector &x, Vector &y) const override
Matrix vector multiplication with Jacobi smoother.
Data type dense matrix using column-major storage.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
int GetOrder(int i) const
Returns the polynomial degree of the i'th finite element.
Mesh * GetMesh() const
Returns the mesh.
bool IsDGSpace() const
Return whether or not the space is discontinuous (L2)
Abstract class for all finite elements.
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
A general function coefficient.
Class for grid function - Vector with associated FE space.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
void SetTrueVector()
Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
const Vector & GetTrueVector() const
Read only access to the (optional) internal true-dof Vector.
FiniteElementSpace * FESpace()
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Wrapper for hypre's ParCSR matrix class.
Parallel smoothers in hypre.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Relax the linear system Ax=b.
Class for integration point with weight.
Class for an integration rule - an Array of IntegrationPoint.
int GetNPoints() const
Returns the number of the points in the integration rule.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Container class for integration rules.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
const FiniteElementSpace * GetNodalFESpace() const
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
void GetElementTransformation(int i, IsoparametricTransformation *ElTr) const
Builds the transformation defining the i-th element in ElTr. ElTr must be allocated in advance and wi...
long long GetGlobalNE() const
Return the total (global) number of elements.
NCMesh * ncmesh
Optional nonconforming mesh extension.
Geometry::Type GetElementBaseGeometry(int i) const
A class for non-conforming AMR. The class is not used directly by the user, rather it is an extension...
int GetNumRootElements()
Return the number of root elements.
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
ParMesh * GetParMesh() const
Class for parallel grid function.
void SetFromTrueDofs(const Vector &tv) override
Set the GridFunction from the given true-dof vector.
ParFiniteElementSpace * ParFESpace() const
@ ClosedUniform
aka closed Newton-Cotes
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
void SetOperator(const Operator &a) override
Set/update the solver for the given operator.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
real_t Min() const
Returns the minimal element of the vector.
real_t size_indicator(const Vector &x)
int material_id(int el_id, const GridFunction &g)
real_t surface_level_set(const Vector &x)
real_t adapt_lim_fun(const Vector &x)
real_t size_indicator_periodic(const Vector &x)
IntegrationRules IntRulesCU(0, Quadrature1D::ClosedUniform)
real_t weight_fun(const Vector &x)
real_t material_indicator_2d(const Vector &x)
IntegrationRules IntRulesLo(0, Quadrature1D::GaussLobatto)
void ConstructSizeGF(GridFunction &size)
void calc_mass_volume(const GridFunction &g, real_t &mass, real_t &vol)
real_t discrete_ori_2d(const Vector &x)
void discrete_aspr_3d(const Vector &x, Vector &v)
void DiffuseField(ParGridFunction &field, int smooth_steps)
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
Helper struct to convert a C++ type to an MPI type.