17using namespace common;
25 const real_t xc = x(0) - 0.5, yc = x(1) - 0.5;
26 const real_t r = sqrt(xc*xc + yc*yc);
31 const real_t xc = x(0) - 0.5, yc = x(1) - 0.5, zc = x(2) - 0.5;
32 const real_t r = sqrt(xc*xc + yc*yc + zc*zc);
42 const real_t xc = x(0) - 0.5, yc = x(1) - 0.5;
43 return std::pow(xc, 4.0) + std::pow(yc, 4.0) - std::pow(0.24, 4.0);
47 const real_t xc = x(0) - 0.5, yc = x(1) - 0.5, zc = x(2) - 0.5;
48 return std::pow(xc, 4.0) + std::pow(yc, 4.0) +
49 std::pow(zc, 4.0) - std::pow(0.24, 4.0);
56 x_current -= x_center;
73 return (phi_t <= 0.0) ? 1.0 : -1.0;
78 real_t phi_p1 = (x(0)-h-t/2) - k*x(1)*x(1);
79 real_t phi_p2 = (x(0)-h+t/2) - k*x(1)*x(1);
80 return (phi_p1 <= 0.0 && phi_p2 >= 0.0) ? 1.0 : -1.0;
85 real_t dx = std::abs(x(0) - xc);
86 real_t dy = std::abs(x(1) - yc);
87 return (dx <= w/2 && dy <= h/2) ? 1.0 : -1.0;
103 real_t return_val = max(in_circle1_val, in_trapezium_val);
109 return_val = max(return_val, in_parabola_val);
112 return_val = max(return_val, in_rectangle_val);
115 return_val = max(return_val, in_rectangle_val2);
122 real_t dx = std::abs(x(0) - xc);
123 real_t dy = std::abs(x(1) - yc);
124 real_t dz = std::abs(x(2) - zc);
125 return (dx <= lx/2 && dy <= ly/2 && dz <= lz/2) ? 1.0 : -1.0;
131 Vector x_pipe_copy = x_pipe_center;
133 x_pipe_copy(pipedir-1) = 0.0;
136 if (dist < radius && xv > minv && xv < maxv)
140 else if (dist ==
radius || (xv == minv && dist <
radius) || (xv == maxv &&
151 return r1 + r2 - std::pow(r1*r1 + r2*r2, 0.5);
156 return r1 + r2 + std::pow(r1*r1 + r2*r2, 0.5);
172 real_t in_cube_val =
in_cube(x, xcc(0), xcc(1), xcc(2), cube_x, cube_y, cube_z);
177 real_t sphere_radius = 0.30;
179 real_t in_return_val = std::min(in_cube_val, in_sphere_val);
184 real_t xmin = 0.5-sphere_radius;
185 real_t xmax = 0.5+sphere_radius;
186 real_t pipe_radius = 0.075;
187 real_t in_pipe_x =
in_pipe(x, pipedir, x_pipe_center, pipe_radius, xmin, xmax);
189 in_return_val = std::min(in_return_val, -1*in_pipe_x);
192 in_pipe_x =
in_pipe(x, pipedir, x_pipe_center, pipe_radius, xmin, xmax);
193 in_return_val = std::min(in_return_val, -1*in_pipe_x);
196 in_pipe_x =
in_pipe(x, pipedir, x_pipe_center, pipe_radius, xmin, xmax);
197 in_return_val = std::min(in_return_val, -1*in_pipe_x);
199 return in_return_val;
206 for (
int i = 0; i < pmesh->
GetNBE(); i++)
214 for (
int j = 0; j < dofs.
Size(); j++)
216 for (
int d = 0; d <
dim; d++)
222 dof_xyz_compare = dof_xyz;
227 for (
int d = 0; d <
dim; d++)
229 if (std::abs(dof_xyz(d)-dof_xyz_compare(d)) < 1.e-10)
238 if (xyz_check[0] == dofs.
Size())
242 else if (xyz_check[1] == dofs.
Size())
253 if (xyz_check[0] == dofs.
Size())
257 else if (xyz_check[1] == dofs.
Size())
261 else if (xyz_check[2] == dofs.
Size())
280 for (
int e = 0; e < pmesh->
GetNE(); e++)
293 int diff_attr_count = 0;
297 bool bdr_element =
false;
298 element_attr[e] = attr1;
299 int target_attr = -1;
300 for (
int f = 0;
f < faces.
Size();
f++)
305 attr2 = elem1 == e ? (int)(mat(elem2)) : (int)(mat(elem1));
306 if (attr1 != attr2 && attr1 == attr_to_switch)
308 diff_attr_count += 1;
320 attr2 = (int)(dof_vals(0));
321 if (attr1 != attr2 && attr1 == attr_to_switch)
323 diff_attr_count += 1;
334 if (diff_attr_count == faces.
Size()-1 && !bdr_element)
336 element_attr[e] = target_attr;
339 for (
int e = 0; e < pmesh->
GetNE(); e++)
341 mat(e) = element_attr[e];
352 const int quad_order = 5,
372 for (
int iter = 0; iter < amr_iter; iter++)
375 for (
int e = 0; e < pmesh.
GetNE(); e++)
387 if (min_val < 0 && max_val >= 0)
389 el_to_refine(e) = 1.0;
394 for (
int inner_iter = 0; inner_iter < 2; inner_iter++)
399 for (
int e = 0; e < pmesh.
GetNE(); e++)
410 el_to_refine(e) = 1.0;
417 for (
int e = 0; e < el_to_refine.
Size(); e++)
419 if (el_to_refine(e) > 0.0)
421 el_to_refine_list.
Append(e);
425 int loc_count = el_to_refine_list.
Size();
426 int glob_count = loc_count;
427 MPI_Allreduce(&loc_count, &glob_count, 1, MPI_INT, MPI_SUM,
449 if (pgf_to_update != NULL)
451 for (
int i = 0; i < pgf_to_update->Size(); i++)
453 (*pgf_to_update)[i]->ParFESpace()->Update();
454 (*pgf_to_update)[i]->Update();
463 const int nDiffuse = 2,
464 const int pLapOrder = 5,
465 const int pLapNewton = 50)
485 filter.
Filter(ls_coeff, filt_gf);
int Size() const
Return the logical size of the array.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
Data type dense matrix using column-major storage.
int GetOrder() const
Return the order (polynomial degree) of the FE collection, corresponding to the order/degree returned...
const FiniteElementCollection * FEColl() const
Mesh * GetMesh() const
Returns the mesh.
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 DofToVDof(int dof, int vd, int ndofs=-1) const
Compute a single vdof corresponding to the index dof and the vector index vd.
A general function coefficient.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
void SetTrueVector()
Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
Arbitrary order H1-conforming (continuous) finite elements.
Class for an integration rule - an Array of IntegrationPoint.
Container class for integration rules.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
Arbitrary order "L2-conforming" discontinuous finite elements.
void GetFaceInfos(int Face, int *Inf1, int *Inf2) const
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Geometry::Type GetElementGeometry(int i) const
const FiniteElementSpace * GetNodalFESpace() const
void SetAttribute(int i, int attr)
Set the attribute of element i.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
void GetFaceElements(int Face, int *Elem1, int *Elem2) const
void GetElementFaces(int i, Array< int > &faces, Array< int > &ori) const
Return the indices and the orientations of all faces of element i.
int GetNBE() const
Returns number of boundary elements.
void GetElementEdges(int i, Array< int > &edges, Array< int > &cor) const
Return the indices and the orientations of all edges of element i.
void SetBdrAttribute(int i, int attr)
Set the attribute of boundary element i.
Abstract parallel finite element space.
void GetElementDofs(int i, Array< int > &dofs, DofTransformation &doftrans) const override
The same as GetElementDofs(), but with a user-allocated DofTransformation object. doftrans must be al...
void Update(bool want_transform=true) override
Class for parallel grid function.
void ExchangeFaceNbrData()
void ProjectDiscCoefficient(VectorCoefficient &coeff) override
Project a discontinuous vector coefficient as a grid function on a continuous finite element space....
ParFiniteElementSpace * ParFESpace() const
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
void Update() override
Transform by the Space UpdateMatrix (e.g., on Mesh change).
void GetElementDofValues(int el, Vector &dof_vals) const override
Class for parallel meshes.
void SetAttributes() override
Determine the sets of unique attribute values in domain and boundary elements.
real_t Norml2() const
Returns the l2 norm of the vector.
real_t Max() const
Returns the maximal element of the vector.
int Size() const
Returns the size of the vector.
real_t Min() const
Returns the minimal element of the vector.
void Filter(ParGridFunction &func, ParGridFunction &ffield)
void ComputeScalarDistance(Coefficient &func, ParGridFunction &fdist)
real_t in_trapezium(const Vector &x, real_t a, real_t b, real_t l)
real_t reactor(const Vector &x)
real_t in_pipe(const Vector &x, int pipedir, Vector x_pipe_center, real_t radius, real_t minv, real_t maxv)
real_t in_cube(const Vector &x, real_t xc, real_t yc, real_t zc, real_t lx, real_t ly, real_t lz)
real_t in_circle(const Vector &x, const Vector &x_center, real_t radius)
real_t in_rectangle(const Vector &x, real_t xc, real_t yc, real_t w, real_t h)
real_t r_intersect(real_t r1, real_t r2)
real_t csg_cubecylsph(const Vector &x)
real_t r_remove(real_t r1, real_t r2)
void ModifyBoundaryAttributesForNodeMovement(ParMesh *pmesh, ParGridFunction &x)
void ModifyAttributeForMarkingDOFS(ParMesh *pmesh, ParGridFunction &mat, int attr_to_switch)
real_t squircle_level_set(const Vector &x)
real_t in_parabola(const Vector &x, real_t h, real_t k, real_t t)
void OptimizeMeshWithAMRAroundZeroLevelSet(ParMesh &pmesh, FunctionCoefficient &ls_coeff, int amr_iter, ParGridFunction &distance_s, const int quad_order=5, Array< ParGridFunction * > *pgf_to_update=NULL)
void ComputeScalarDistanceFromLevelSet(ParMesh &pmesh, FunctionCoefficient &ls_coeff, ParGridFunction &distance_s, const int nDiffuse=2, const int pLapOrder=5, const int pLapNewton=50)
real_t circle_level_set(const Vector &x)
real_t r_union(real_t r1, real_t r2)
real_t AvgElementSize(ParMesh &pmesh)
void DiffuseField(ParGridFunction &field, int smooth_steps)
std::function< real_t(const Vector &)> f(real_t mass_coeff)