13 #include "../common/mfem-common.hpp" 25 const double xc = x(0) - 0.5, yc = x(1) - 0.5;
26 const double r = sqrt(xc*xc + yc*yc);
31 const double xc = x(0) - 0.5, yc = x(1) - 0.5, zc = x(2) - 0.5;
32 const double r = sqrt(xc*xc + yc*yc + zc*zc);
40 x_current -= x_center;
41 double dist = x_current.
Norml2();
56 double phi_t = x(1) + (
a-
b)*x(0)/l -
a;
57 return (phi_t <= 0.0) ? 1.0 : -1.0;
62 double phi_p1 = (x(0)-h-
t/2) - k*x(1)*x(1);
63 double phi_p2 = (x(0)-h+
t/2) - k*x(1)*x(1);
64 return (phi_p1 <= 0.0 && phi_p2 >= 0.0) ? 1.0 : -1.0;
69 double dx = fabs(x(0) - xc);
70 double dy = fabs(x(1) - yc);
71 return (dx <= w/2 && dy <= h/2) ? 1.0 : -1.0;
81 double in_circle1_val =
in_circle(x, x_circle1, 0.2);
85 double in_trapezium_val =
in_trapezium(x, 0.05, 0.1, r2-r1);
87 double return_val = max(in_circle1_val, in_trapezium_val);
93 return_val = max(return_val, in_parabola_val);
95 double in_rectangle_val =
in_rectangle(x, 0.99, 0.0, 0.12, 0.35);
96 return_val = max(return_val, in_rectangle_val);
98 double in_rectangle_val2 =
in_rectangle(x, 0.99, 0.5, 0.12, 0.28);
99 return_val = max(return_val, in_rectangle_val2);
104 double ly,
double lz)
106 double dx = fabs(x(0) - xc);
107 double dy = fabs(x(1) - yc);
108 double dz = fabs(x(2) - zc);
109 return (dx <= lx/2 && dy <= ly/2 && dz <= lz/2) ? 1.0 : -1.0;
113 double radius,
double minv,
double maxv)
115 Vector x_pipe_copy = x_pipe_center;
117 x_pipe_copy(pipedir-1) = 0.0;
118 double dist = x_pipe_copy.
Norml2();
119 double xv = x(pipedir-1);
120 if (dist < radius && xv > minv && xv < maxv)
124 else if (dist ==
radius || (xv == minv && dist <
radius) || (xv == maxv &&
135 return r1 + r2 - std::pow(r1*r1 + r2*r2, 0.5);
140 return r1 + r2 + std::pow(r1*r1 + r2*r2, 0.5);
152 double cube_x = 0.25*2;
153 double cube_y = 0.25*2;
154 double cube_z = 0.25*2;
156 double in_cube_val =
in_cube(x, xcc(0), xcc(1), xcc(2), cube_x, cube_y, cube_z);
161 double sphere_radius = 0.30;
162 double in_sphere_val =
in_circle(x, x_circle_c, sphere_radius);
163 double in_return_val = std::min(in_cube_val, in_sphere_val);
168 double xmin = 0.5-sphere_radius;
169 double xmax = 0.5+sphere_radius;
170 double pipe_radius = 0.075;
171 double in_pipe_x =
in_pipe(x, pipedir, x_pipe_center, pipe_radius, xmin, xmax);
173 in_return_val = std::min(in_return_val, -1*in_pipe_x);
176 in_pipe_x =
in_pipe(x, pipedir, x_pipe_center, pipe_radius, xmin, xmax);
177 in_return_val = std::min(in_return_val, -1*in_pipe_x);
180 in_pipe_x =
in_pipe(x, pipedir, x_pipe_center, pipe_radius, xmin, xmax);
181 in_return_val = std::min(in_return_val, -1*in_pipe_x);
183 return in_return_val;
190 for (
int i = 0; i < pmesh->
GetNBE(); i++)
198 for (
int j = 0; j < dofs.
Size(); j++)
200 for (
int d = 0; d <
dim; d++)
206 dof_xyz_compare = dof_xyz;
211 for (
int d = 0; d <
dim; d++)
213 if (std::fabs(dof_xyz(d)-dof_xyz_compare(d)) < 1.e-10)
222 if (xyz_check[0] == dofs.
Size())
226 else if (xyz_check[1] == dofs.
Size())
237 if (xyz_check[0] == dofs.
Size())
241 else if (xyz_check[1] == dofs.
Size())
245 else if (xyz_check[2] == dofs.
Size())
264 for (
int e = 0; e < pmesh->
GetNE(); e++)
277 int diff_attr_count = 0;
281 bool bdr_element =
false;
282 element_attr[e] = attr1;
283 int target_attr = -1;
284 for (
int f = 0;
f < faces.
Size();
f++)
289 attr2 = elem1 == e ? (int)(mat(elem2)) : (
int)(mat(elem1));
290 if (attr1 != attr2 && attr1 == attr_to_switch)
292 diff_attr_count += 1;
304 attr2 = (int)(dof_vals(0));
305 if (attr1 != attr2 && attr1 == attr_to_switch)
307 diff_attr_count += 1;
318 if (diff_attr_count == faces.
Size()-1 && !bdr_element)
320 element_attr[e] = target_attr;
323 for (
int e = 0; e < pmesh->
GetNE(); e++)
325 mat(e) = element_attr[e];
336 const int quad_order = 5,
356 for (
int iter = 0; iter < amr_iter; iter++)
359 for (
int e = 0; e < pmesh.
GetNE(); e++)
364 h1fespace.GetElementDofs(e, dofs);
368 double min_val = x_vals.
Min();
369 double max_val = x_vals.
Max();
371 if (min_val < 0 && max_val >= 0)
373 el_to_refine(e) = 1.0;
378 for (
int inner_iter = 0; inner_iter < 2; inner_iter++)
383 for (
int e = 0; e < pmesh.
GetNE(); e++)
387 lhfespace.GetElementDofs(e, dofs);
391 double max_val = x_vals.
Max();
394 el_to_refine(e) = 1.0;
401 for (
int e = 0; e < el_to_refine.
Size(); e++)
403 if (el_to_refine(e) > 0.0)
405 el_to_refine_list.
Append(e);
409 int loc_count = el_to_refine_list.
Size();
410 int glob_count = loc_count;
411 MPI_Allreduce(&loc_count, &glob_count, 1, MPI_INT, MPI_SUM,
433 if (pgf_to_update != NULL)
435 for (
int i = 0; i < pgf_to_update->Size(); i++)
437 (*pgf_to_update)[i]->ParFESpace()->Update();
438 (*pgf_to_update)[i]->Update();
447 const int nDiffuse = 2,
448 const int pLapOrder = 5,
449 const int pLapNewton = 50)
469 filter.
Filter(ls_coeff, filt_gf);
double in_circle(const Vector &x, const Vector &x_center, double radius)
virtual void GetElementDofValues(int el, Vector &dof_vals) const
Class for an integration rule - an Array of IntegrationPoint.
const FiniteElementSpace * GetNodalFESpace() const
void GetElementEdges(int i, Array< int > &edges, Array< int > &cor) const
Return the indices and the orientations of all edges of element i.
void ExchangeFaceNbrData()
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
int Dimension() const
Dimension of the reference space used within the elements.
void ModifyAttributeForMarkingDOFS(ParMesh *pmesh, ParGridFunction &mat, int attr_to_switch)
void Filter(ParGridFunction &func, ParGridFunction &ffield)
virtual void Update(bool want_transform=true)
int GetOrder() const
Return the order (polynomial degree) of the FE collection, corresponding to the order/degree returned...
virtual DofTransformation * GetBdrElementDofs(int bel, Array< int > &dofs) const
Returns indices of degrees of freedom for boundary element 'bel'. The returned indices are offsets in...
int Size() const
Returns the size of the vector.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Container class for integration rules.
Data type dense matrix using column-major storage.
virtual void ProjectDiscCoefficient(VectorCoefficient &coeff)
Project a discontinuous vector coefficient as a grid function on a continuous finite element space...
Abstract parallel finite element space.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
double in_parabola(const Vector &x, double h, double k, double t)
int GetNBE() const
Returns number of boundary elements.
void GetFaceElements(int Face, int *Elem1, int *Elem2) const
void SetTrueVector()
Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
void GetElementFaces(int i, Array< int > &faces, Array< int > &ori) const
Return the indices and the orientations of all faces of element i.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
double reactor(const Vector &x)
int Append(const T &el)
Append element 'el' to array, resize if necessary.
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
const FiniteElementCollection * FEColl() const
void OptimizeMeshWithAMRAroundZeroLevelSet(ParMesh &pmesh, FunctionCoefficient &ls_coeff, int amr_iter, ParGridFunction &distance_s, const int quad_order=5, Array< ParGridFunction *> *pgf_to_update=NULL)
double in_cube(const Vector &x, double xc, double yc, double zc, double lx, double ly, double lz)
double csg_cubecylsph(const Vector &x)
void GetFaceInfos(int Face, int *Inf1, int *Inf2) const
double in_trapezium(const Vector &x, double a, double b, double l)
double r_union(double r1, double r2)
Geometry::Type GetElementGeometry(int i) const
Mesh * GetMesh() const
Returns the mesh.
double Min() const
Returns the minimal element of the vector.
ParFiniteElementSpace * ParFESpace() const
void SetBdrAttribute(int i, int attr)
Set the attribute of boundary element i.
double Max() const
Returns the maximal element of the vector.
void SetAttributes() override
Determine the sets of unique attribute values in domain and boundary elements.
int GetNE() const
Returns number of elements.
void ModifyBoundaryAttributesForNodeMovement(ParMesh *pmesh, ParGridFunction &x)
void ComputeScalarDistance(Coefficient &func, ParGridFunction &fdist)
double circle_level_set(const Vector &x)
void DiffuseField(ParGridFunction &field, int smooth_steps)
double r_remove(double r1, double r2)
double Norml2() const
Returns the l2 norm of the vector.
int Size() const
Return the logical size of the array.
A general function coefficient.
void SetAttribute(int i, int attr)
Set the attribute of element i.
int DofToVDof(int dof, int vd, int ndofs=-1) const
Compute a single vdof corresponding to the index dof and the vector index vd.
double in_pipe(const Vector &x, int pipedir, Vector x_pipe_center, double radius, double minv, double maxv)
Arbitrary order H1-conforming (continuous) finite elements.
double in_rectangle(const Vector &x, double xc, double yc, double w, double h)
void ComputeScalarDistanceFromLevelSet(ParMesh &pmesh, FunctionCoefficient &ls_coeff, ParGridFunction &distance_s, const int nDiffuse=2, const int pLapOrder=5, const int pLapNewton=50)
Class for parallel grid function.
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Class for parallel meshes.
double r_intersect(double r1, double r2)
double AvgElementSize(ParMesh &pmesh)
Arbitrary order "L2-conforming" discontinuous finite elements.
double f(const Vector &p)