31 int new_nodes_ordering)
38 ncomp =
space->GetVDim();
41 const int pnt_cnt = field0.
Size() / ncomp;
45 for (
int i = 0; i < ncomp; i++)
49 new_field_temp.
MakeRef(new_field, i*pnt_cnt, pnt_cnt);
53 new_field_temp.
SetSize(pnt_cnt);
54 for (
int j = 0; j < pnt_cnt; j++)
56 new_field_temp(j) = new_field(i + j*ncomp);
59 ComputeAtNewPositionScalar(new_nodes, new_field_temp);
62 for (
int j = 0; j < pnt_cnt; j++)
64 new_field(i + j*ncomp) = new_field_temp(j);
73void AdvectorCG::ComputeAtNewPositionScalar(
const Vector &new_nodes,
81 MFEM_VERIFY(m != NULL,
"No mesh has been given to the AdaptivityEvaluator.");
110 MFEM_VERIFY(oper != NULL,
111 "No FE space has been given to the AdaptivityEvaluator.");
112 ode_solver.
Init(*oper);
115 real_t h_min = std::numeric_limits<real_t>::infinity();
116 for (
int i = 0; i < m->
GetNE(); i++)
121 const int s = new_field.
Size();
124 for (
int i = 0; i <
s; i++)
131 v_max = std::max(v_max,
vel);
137 real_t v_loc = v_max, h_loc = h_min;
155 v_max = std::sqrt(v_max);
156 real_t dt = dt_scale * h_min / v_max;
159 bool last_step =
false;
167 ode_solver.
Step(new_field,
t, dt);
184 for (
int i = 0; i <
s; i++)
186 if (new_field(i) < glob_minv) { new_field(i) = glob_minv; }
187 if (new_field(i) > glob_maxv) { new_field(i) = glob_maxv; }
202 x0(x_start), x_now(*fes.
GetMesh()->GetNodes()),
203 u(
vel), u_coeff(&
u), M(&fes), K(&fes), al(al)
226 K.BilinearForm::operator=(0.0);
230 M.BilinearForm::operator=(0.0);
248#ifdef MFEM_USE_SINGLE
251 const real_t rtol = 1e-12;
256 lin_solver.
Mult(rhs, di_dt);
268 x0(x_start), x_now(*pfes.
GetMesh()->GetNodes()),
269 u(
vel), u_coeff(&
u), M(&pfes), K(&pfes), al(al)
300 K.BilinearForm::operator=(0.0);
304 M.BilinearForm::operator=(0.0);
329#ifdef MFEM_USE_SINGLE
337 lin_solver.
Mult(*RHS, X);
356 const real_t rel_bbox_el = 0.1;
357 const real_t newton_tol = 1.0e-12;
358 const int npts_at_once = 256;
377 finder->
Setup(*m, rel_bbox_el, newton_tol, npts_at_once);
380 field0_gf = init_field;
385 int new_nodes_ordering)
387 finder->
Interpolate(new_nodes, field0_gf, new_field, new_nodes_ordering);
399 MFEM_VERIFY(!(
parallel && p_nlf == NULL),
"Invalid Operator subclass.");
408 MFEM_VERIFY(!(serial && nlf == NULL),
"Invalid Operator subclass.");
421 if (!cP) { x_out_loc = x; }
422 else { cP->
Mult(x, x_out_loc); }
432 real_t avg_surf_fit_err, max_surf_fit_err = 0.0;
440 mfem::out <<
"TMOPNewtonSolver converged "
441 "based on the surface fitting error.\n";
451 mfem::out <<
"TMOPNewtonSolver converged "
452 "based on max number of times surface fitting weight can"
462 const bool untangling = (min_detT_in <= 0.0) ?
true :
false;
463 const real_t untangle_factor = 1.5;
468 MFEM_VERIFY(
min_det_ptr != NULL,
" Initial mesh was valid, but"
469 " intermediate mesh is invalid. Contact TMOP Developers.");
471 "This setup is not supported. Contact TMOP Developers.");
475 const bool have_b = (
b.Size() ==
Height());
478 bool x_out_ok =
false;
479 real_t energy_out = 0.0, min_detT_out;
489 for (
int i = 0; i < 12; i++)
492 add(x, -scale,
c, x_out);
496 if (!cP) { x_out_loc = x_out; }
497 else { cP->
Mult(x_out, x_out_loc); }
510 mfem::out <<
"Scale = " << scale <<
" Neg det(J) found.\n";
512 scale *= detJ_factor;
continue;
514 if (untangling ==
true && min_detT_out < *
min_det_ptr)
519 mfem::out <<
"Scale = " << scale <<
" Neg det(J) decreased.\n";
521 scale *= detJ_factor;
continue;
527 if (untangling) { x_out_ok =
true;
break; }
532 real_t avg_fit_err, max_fit_err = 0.0;
541 mfem::out <<
"Scale = " << scale <<
" Surf fit err increased.\n";
543 scale *= 0.5;
continue;
556 if (energy_out > energy_in + 0.2*fabs(energy_in) ||
557 std::isnan(energy_out) != 0)
561 mfem::out <<
"Scale = " << scale <<
" Increasing energy: "
562 << energy_in <<
" --> " << energy_out <<
'\n';
564 scale *= 0.5;
continue;
569 if (have_b) {
r -=
b; }
572 if (norm_out > 1.2*norm_in)
576 mfem::out <<
"Scale = " << scale <<
" Norm increased: "
577 << norm_in <<
" --> " << norm_out <<
'\n';
579 scale *= 0.5;
continue;
581 else { x_out_ok =
true;
break; }
587 if (min_detT_out > 0.0)
592 {
mfem::out <<
"The mesh has been untangled at the used points!\n"; }
594 else { *
min_det_ptr = untangle_factor * min_detT_out; }
603 << min_detT_in <<
" -> " << min_detT_out
604 <<
" with " << scale <<
" scaling.\n";
609 << energy_in <<
" --> " << energy_out <<
" or "
610 << (energy_in - energy_out) / energy_in * 100.0
611 <<
"% with " << scale <<
" scaling.\n";
615 if (x_out_ok ==
false) { scale = 0.0; }
629 for (
int i = 0; i < integs.
Size(); i++)
640 for (
int j = 0; j < ati.
Size(); j++)
642 ati[j]->UpdateSurfaceFittingWeight(factor);
657 for (
int i = 0; i < integs.
Size(); i++)
669 for (
int j = 0; j < ati.
Size(); j++)
671 weight = ati[j]->GetSurfaceFittingWeight();
689 real_t err_avg_loc, err_max_loc;
690 for (
int i = 0; i < integs.
Size(); i++)
698 err_avg = std::max(err_avg_loc, err_avg);
699 err_max = std::max(err_max_loc, err_max);
706 for (
int j = 0; j < ati.
Size(); j++)
708 if (ati[j]->IsSurfaceFittingEnabled())
710 ati[j]->GetSurfaceFittingErrors(x_loc, err_avg_loc, err_max_loc);
711 err_avg = std::max(err_avg_loc, err_avg);
712 err_max = std::max(err_max_loc, err_max);
729 for (
int i = 0; i < integs.
Size(); i++)
741 for (
int j = 0; j < ati.
Size(); j++)
743 dtc = ati[j]->GetDiscreteAdaptTC();
774 for (
int i = 0; i < integs.
Size(); i++)
789 for (
int j = 0; j < ati.
Size(); j++)
791 ati[j]->UpdateAfterMeshPositionChange(x_loc, *x_fes);
794 ati[j]->ComputeUntangleMetricQuantiles(x_loc, *x_fes);
814 mfem::out <<
"Avg/Max surface fitting error: " <<
817 mfem::out <<
"Min/Max surface fitting weight: " <<
818 weights.
Min() <<
" " << weights.
Max() <<
"\n";
849 for (
int i = 0; i < NE; i++)
860 for (
int j = 0; j < nsp; j++)
864 min_detJ = std::min(min_detJ, Jpr.
Det());
873 real_t min_detT_all = min_detJ;
880 p_nlf->ParFESpace()->GetComm());
885 min_detT_all /= Wideal.
Det();
895 char *title,
int position)
904 sock.
open(
"localhost", 19916);
905 sock <<
"solution\n";
911 sock <<
"window_title '"<< title <<
"'\n"
912 <<
"window_geometry "
913 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
923 char *title,
int position)
930 sock <<
"solution\n";
934 sock <<
"window_title '"<< title <<
"'\n"
935 <<
"window_geometry "
936 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
ParFiniteElementSpace * pfes
virtual void ComputeAtNewPosition(const Vector &new_nodes, Vector &new_field, int new_nodes_ordering=Ordering::byNODES)
virtual void SetInitialField(const Vector &init_nodes, const Vector &init_field)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
T Min() const
Find the minimal element in the array, using the comparison operator < for class T.
int Size() const
Return the logical size of the array.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
@ GaussLobatto
Closed type.
Conjugate gradient method.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
virtual void Mult(const Vector &b, Vector &x) const
Iterative solution of the linear system using the Conjugate Gradient method.
Data type for scaled Jacobi-type smoother of sparse matrix.
Data type dense matrix using column-major storage.
real_t * Data() const
Returns the matrix data array.
static MemoryType GetDeviceMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
void ResetUpdateFlags()
Used in combination with the Update methods to avoid extra computations.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points....
void Setup(Mesh &m, const double bb_t=0.1, const double newt_tol=1.0e-12, const int npt_max=256)
virtual void Interpolate(const GridFunction &field_in, Vector &field_out)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indices of degrees of freedom for the i'th element. The returned indices are offsets into an ...
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
Ordering::Type GetOrdering() const
Return the ordering method.
int GetNE() const
Returns number of elements in the mesh.
const SparseMatrix * GetConformingProlongation() const
The returned SparseMatrix is owned by the FiniteElementSpace.
const FiniteElementCollection * FEColl() const
Mesh * GetMesh() const
Returns the mesh.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
virtual void CalcDShape(const IntegrationPoint &ip, DenseMatrix &dshape) const =0
Evaluate the gradients of all shape functions of a scalar finite element in reference space at the gi...
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
int GetDof() const
Returns the number of degrees of freedom in the finite element.
const DenseMatrix & GetGeomToPerfGeomJac(int GeomType) const
Class for grid function - Vector with associated FE space.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
FiniteElementSpace * FESpace()
virtual void SetSpace(FiniteElementSpace *f)
Associate a new FiniteElementSpace with the GridFunction.
Wrapper for hypre's parallel vector class.
Parallel smoothers in hypre.
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.
virtual void ComputeAtNewPosition(const Vector &new_nodes, Vector &new_field, int new_nodes_ordering=Ordering::byNODES)
virtual void SetInitialField(const Vector &init_nodes, const Vector &init_field)
PrintLevel print_options
Output behavior for the iterative solver.
void SetRelTol(real_t rtol)
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void SetMaxIter(int max_it)
void SetAbsTol(real_t atol)
real_t Norm(const Vector &x) const
Return the inner product norm of x, using the inner product defined by Dot()
Arbitrary order "L2-conforming" discontinuous finite elements.
void NodesUpdated()
This function should be called after the mesh node coordinates have been updated externally,...
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
real_t GetElementSize(int i, int type=0)
Get the size of the i-th element relative to the perfect reference element.
void GetNodes(Vector &node_coord) const
void SetNodes(const Vector &node_coord)
Updates the vertex/node locations. Invokes NodesUpdated().
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
Pointer to an Operator of a specified type.
void Reset(OpType *A, bool own_A=true)
Reset the OperatorHandle to the given OpType pointer, A.
Jacobi smoothing for a given bilinear form (no matrix necessary).
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
Performs a single remap advection step in parallel.
ParAdvectorCGOper(const Vector &x_start, GridFunction &vel, ParFiniteElementSpace &pfes, AssemblyLevel al=AssemblyLevel::LEGACY, MemoryType mt=MemoryType::DEFAULT)
VectorGridFunctionCoefficient u_coeff
virtual void Mult(const Vector &ind, Vector &di_dt) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x,...
Abstract parallel finite element space.
const Operator * GetProlongationMatrix() const override
The returned Operator is owned by the FiniteElementSpace.
ParMesh * GetParMesh() const
Class for parallel grid function.
void ParallelAssemble(Vector &tv) const
Returns the vector assembled on the true dofs.
void SaveAsOne(const char *fname, int precision=16) const
Class for parallel meshes.
void PrintAsOne(std::ostream &out=mfem::out, const std::string &comments="") const
void Init(TimeDependentOperator &f_) override
Associate a TimeDependentOperator with the ODE solver.
void Step(Vector &x, real_t &t, real_t &dt) override
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in].
Performs a single remap advection step in serial.
VectorGridFunctionCoefficient u_coeff
SerialAdvectorCGOper(const Vector &x_start, GridFunction &vel, FiniteElementSpace &fes, AssemblyLevel al=AssemblyLevel::LEGACY)
virtual void Mult(const Vector &ind, Vector &di_dt) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x,...
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
const Array< TMOP_Integrator * > & GetTMOPIntegrators() const
virtual void ProcessNewState(const Vector &x) const
virtual real_t ComputeScalingFactor(const Vector &x, const Vector &b) const
virtual void GetSurfaceFittingError(const Vector &x_loc, real_t &err_avg, real_t &err_max) const
real_t surf_fit_scale_factor
real_t surf_fit_rel_change_threshold
real_t MinDetJpr_3D(const FiniteElementSpace *, const Vector &) const
real_t surf_fit_max_threshold
const IntegrationRule & GetIntegrationRule(const FiniteElement &el) const
real_t surf_fit_err_avg_prvs
void UpdateSurfaceFittingWeight(real_t factor) const
Update surface fitting weight as surf_fit_weight *= factor.
bool update_surf_fit_coeff
real_t MinDetJpr_2D(const FiniteElementSpace *, const Vector &) const
bool compute_metric_quantile_flag
real_t min_detJ_threshold
real_t ComputeMinDet(const Vector &x_loc, const FiniteElementSpace &fes) const
void GetSurfaceFittingWeight(Array< real_t > &weights) const
Get the surface fitting weight for all the TMOP integrators.
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.
void ComputeUntangleMetricQuantiles(const Vector &x, const FiniteElementSpace &fes)
real_t GetSurfaceFittingWeight()
Get the surface fitting weight.
bool IsSurfaceFittingEnabled()
void UpdateAfterMeshPositionChange(const Vector &x_new, const FiniteElementSpace &x_fes)
void GetSurfaceFittingErrors(const Vector &pos, real_t &err_avg, real_t &err_max)
DiscreteAdaptTC * GetDiscreteAdaptTC() const
void UpdateSurfaceFittingWeight(real_t factor)
Update the surface fitting weight as surf_fit_coeff *= factor;.
Abstract class for local mesh quality metrics in the target-matrix optimization paradigm (TMOP) by P....
Base class representing target-matrix construction algorithms for mesh optimization via the target-ma...
Base abstract class for first order time dependent operators.
virtual real_t GetTime() const
Read the currently set time.
real_t Max() const
Returns the maximal element of the vector.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
virtual real_t * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
real_t Min() const
Returns the minimal element of the vector.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
real_t u(const Vector &xvec)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void add(const Vector &v1, const Vector &v2, Vector &v)
AssemblyLevel
Enumeration defining the assembly level for bilinear and nonlinear form classes derived from Operator...
void vis_tmop_metric_s(int order, TMOP_QualityMetric &qm, const TargetConstructor &tc, Mesh &mesh, char *title, int position)
void InterpolateTMOP_QualityMetric(TMOP_QualityMetric &metric, const TargetConstructor &tc, const Mesh &mesh, GridFunction &metric_gf)
Interpolates the metric's values at the nodes of metric_gf.
void vis_tmop_metric_p(int order, TMOP_QualityMetric &qm, const TargetConstructor &tc, ParMesh &pmesh, char *title, int position)
bool UsesTensorBasis(const FiniteElementSpace &fes)
Return true if the mesh contains only one topology and the elements are tensor elements.
void subtract(const Vector &x, const Vector &y, Vector &z)
ComplexDenseMatrix * MultAtB(const ComplexDenseMatrix &A, const ComplexDenseMatrix &B)
Multiply the complex conjugate transpose of a matrix A with a matrix B. A^H*B.
MemoryType
Memory types supported by MFEM.
std::function< real_t(const Vector &)> f(real_t mass_coeff)
void vel(const Vector &x, real_t t, Vector &u)
bool iterations
Detailed information about each iteration will be reported to mfem::out.
bool first_and_last
Information about the first and last iteration will be printed to mfem::out.
bool summary
A summary of the solver process will be reported after the last iteration to mfem::out.
Helper struct to convert a C++ type to an MPI type.