15 #include "../general/osockstream.hpp"
33 const int pnt_cnt = new_field.
Size()/
ncomp;
37 for (
int i = 0; i <
ncomp; i++)
39 new_field_temp.
MakeRef(new_field, i*pnt_cnt, pnt_cnt);
40 ComputeAtNewPositionScalar(new_nodes, new_field_temp);
47 void AdvectorCG::ComputeAtNewPositionScalar(
const Vector &new_nodes,
55 MFEM_VERIFY(m != NULL,
"No mesh has been given to the AdaptivityEvaluator.");
60 double minv = new_field.
Min(), maxv = new_field.
Max();
84 MFEM_VERIFY(oper != NULL,
85 "No FE space has been given to the AdaptivityEvaluator.");
86 ode_solver.
Init(*oper);
90 for (
int i = 0; i < m->
GetNE(); i++)
95 const int s = new_field.
Size();
98 for (
int i = 0; i <
s; i++)
101 for (
int j = 0; j <
dim; j++)
103 vel +=
u(i+j*s)*
u(i+j*s);
105 v_max = std::max(v_max, vel);
111 double v_loc = v_max, h_loc = h_min;
112 MPI_Allreduce(&v_loc, &v_max, 1, MPI_DOUBLE, MPI_MAX,
pfes->
GetComm());
113 MPI_Allreduce(&h_loc, &h_min, 1, MPI_DOUBLE, MPI_MIN,
pfes->
GetComm());
128 double dt = dt_scale * h_min / v_max;
131 bool last_step =
false;
132 for (
int ti = 1; !last_step; ti++)
139 ode_solver.
Step(new_field, t, dt);
142 double glob_minv = minv,
147 MPI_Allreduce(&minv, &glob_minv, 1, MPI_DOUBLE, MPI_MIN,
pfes->
GetComm());
148 MPI_Allreduce(&maxv, &glob_maxv, 1, MPI_DOUBLE, MPI_MAX,
pfes->
GetComm());
154 for (
int i = 0; i <
s; i++)
156 if (new_field(i) < glob_minv) { new_field(i) = glob_minv; }
157 if (new_field(i) > glob_maxv) { new_field(i) = glob_maxv; }
172 x0(x_start), x_now(*fes.
GetMesh()->GetNodes()),
173 u(vel), u_coeff(&
u), M(&fes), K(&fes), al(al)
200 K.BilinearForm::operator=(0.0);
204 M.BilinearForm::operator=(0.0);
225 lin_solver.
Mult(rhs, di_dt);
237 x0(x_start), x_now(*pfes.
GetMesh()->GetNodes()),
238 u(vel), u_coeff(&
u), M(&pfes), K(&pfes), al(al)
273 K.BilinearForm::operator=(0.0);
277 M.BilinearForm::operator=(0.0);
301 lin_solver.SetOperator(*Mop);
302 lin_solver.SetRelTol(1e-8);
303 lin_solver.SetAbsTol(0.0);
304 lin_solver.SetMaxIter(100);
305 lin_solver.SetPrintLevel(0);
306 lin_solver.Mult(*RHS, X);
314 #ifdef MFEM_USE_GSLIB
325 const double rel_bbox_el = 0.1;
326 const double newton_tol = 1.0e-12;
327 const int npts_at_once = 256;
346 finder->
Setup(*m, rel_bbox_el, newton_tol, npts_at_once);
349 field0_gf = init_field;
357 finder->
Interpolate(new_nodes, field0_gf, new_field);
366 double energy_in = 0.0;
369 MFEM_VERIFY(!(
parallel && p_nlf == NULL),
"Invalid Operator subclass.");
378 MFEM_VERIFY(!(serial && nlf == NULL),
"Invalid Operator subclass.");
391 if (!cP) { x_out_loc = x; }
392 else { cP->
Mult(x, x_out_loc); }
404 double avg_err, max_err;
410 mfem::out <<
"TMOPNewtonSolver converged "
411 "based on the surface fitting error.\n";
421 const bool untangling = (min_detT_in <= 0.0) ?
true :
false;
422 const double untangle_factor = 1.5;
427 MFEM_VERIFY(
min_det_ptr != NULL,
" Initial mesh was valid, but"
428 " intermediate mesh is invalid. Contact TMOP Developers.");
435 bool x_out_ok =
false;
436 double energy_out = 0.0, min_detT_out;
437 const double norm_in =
Norm(
r);
439 const double detJ_factor = (
solver_type == 1) ? 0.25 : 0.5;
442 for (
int i = 0; i < 12; i++)
445 add(x, -scale,
c, x_out);
449 if (!cP) { x_out_loc = x_out; }
450 else { cP->
Mult(x_out, x_out_loc); }
461 if (untangling ==
false && min_detT_out < 0.0)
466 mfem::out <<
"Scale = " << scale <<
" Neg det(J) found.\n";
468 scale *= detJ_factor;
continue;
470 if (untangling ==
true && min_detT_out < *
min_det_ptr)
475 mfem::out <<
"Scale = " << scale <<
" Neg det(J) decreased.\n";
477 scale *= detJ_factor;
continue;
483 if (untangling) { x_out_ok =
true;
break; }
498 if (energy_out > energy_in + 0.2*fabs(energy_in) ||
499 std::isnan(energy_out) != 0)
503 mfem::out <<
"Scale = " << scale <<
" Increasing energy: "
504 << energy_in <<
" --> " << energy_out <<
'\n';
506 scale *= 0.5;
continue;
510 oper->
Mult(x_out,
r);
511 if (have_b) {
r -=
b; }
512 double norm_out =
Norm(
r);
514 if (norm_out > 1.2*norm_in)
518 mfem::out <<
"Scale = " << scale <<
" Norm increased: "
519 << norm_in <<
" --> " << norm_out <<
'\n';
521 scale *= 0.5;
continue;
523 else { x_out_ok =
true;
break; }
529 if (min_detT_out > 0.0)
534 {
mfem::out <<
"The mesh has been untangled at the used points!\n"; }
536 else { *
min_det_ptr = untangle_factor * min_detT_out; }
545 << min_detT_in <<
" -> " << min_detT_out
546 <<
" with " << scale <<
" scaling.\n";
551 << energy_in <<
" --> " << energy_out <<
" or "
552 << (energy_in - energy_out) / energy_in * 100.0
553 <<
"% with " << scale <<
" scaling.\n";
557 if (x_out_ok ==
false) { scale = 0.0; }
570 for (
int i = 0; i < integs.
Size(); i++)
581 for (
int j = 0; j < ati.
Size(); j++)
583 ati[j]->UpdateSurfaceFittingWeight(factor);
598 for (
int i = 0; i < integs.
Size(); i++)
610 for (
int j = 0; j < ati.
Size(); j++)
612 weight = ati[j]->GetSurfaceFittingWeight();
620 double &err_max)
const
629 double err_avg_loc, err_max_loc;
630 for (
int i = 0; i < integs.
Size(); i++)
638 err_avg = std::fmax(err_avg_loc, err_avg);
639 err_max = std::fmax(err_max_loc, err_max);
646 for (
int j = 0; j < ati.
Size(); j++)
648 if (ati[j]->IsSurfaceFittingEnabled())
650 ati[j]->GetSurfaceFittingErrors(err_avg_loc, err_max_loc);
651 err_avg = std::fmax(err_avg_loc, err_avg);
652 err_max = std::fmax(err_max_loc, err_max);
669 for (
int i = 0; i < integs.
Size(); i++)
681 for (
int j = 0; j < ati.
Size(); j++)
683 dtc = ati[j]->GetDiscreteAdaptTC();
697 for (
int i = 0; i < integs.
Size(); i++)
710 for (
int j = 0; j < ati.
Size(); j++)
712 ati[j]->UpdateAfterMeshPositionChange(x_loc);
713 ati[j]->ComputeFDh(x_loc, *pfesc);
734 for (
int i = 0; i < integs.
Size(); i++)
747 for (
int j = 0; j < ati.
Size(); j++)
749 ati[j]->UpdateAfterMeshPositionChange(x_loc);
750 ati[j]->ComputeFDh(x_loc, *fesc);
763 double surf_fit_err_max = -10;
764 double surf_fit_err_avg = -10;
773 mfem::out <<
"Avg/Max surface fitting error: " <<
774 surf_fit_err_avg <<
" " <<
775 surf_fit_err_max <<
"\n";
776 mfem::out <<
"Min/Max surface fitting weight: " <<
777 weights.
Min() <<
" " << weights.
Max() <<
"\n";
784 if (rel_change_surf_fit_err < 1.e-2)
794 const Vector &x_new)
const
796 const bool update_flag =
true;
820 for (
int i = 0; i < NE; i++)
831 for (
int j = 0; j < nsp; j++)
835 min_detJ = std::min(min_detJ, Jpr.
Det());
844 double min_detT_all = min_detJ;
849 MPI_Allreduce(&min_detJ, &min_detT_all, 1, MPI_DOUBLE, MPI_MIN,
850 p_nlf->ParFESpace()->GetComm());
855 min_detT_all /= Wideal.
Det();
865 char *title,
int position)
874 sock.
open(
"localhost", 19916);
875 sock <<
"solution\n";
881 sock <<
"window_title '"<< title <<
"'\n"
882 <<
"window_geometry "
883 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
893 char *title,
int position)
900 sock <<
"solution\n";
904 sock <<
"window_title '"<< title <<
"'\n"
905 <<
"window_geometry "
906 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
int GetNPoints() const
Returns the number of the points in the integration rule.
VectorGridFunctionCoefficient u_coeff
void vis_tmop_metric_p(int order, TMOP_QualityMetric &qm, const TargetConstructor &tc, ParMesh &pmesh, char *title, int position)
virtual void Interpolate(const GridFunction &field_in, Vector &field_out)
virtual double GetTime() const
Read the currently set time.
int Size() const
Return the logical size of the array.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Conjugate gradient method.
int GetDim() const
Returns the reference space dimension for the finite element.
AssemblyLevel
Enumeration defining the assembly level for bilinear and nonlinear form classes derived from Operator...
Class for an integration rule - an Array of IntegrationPoint.
Class for grid function - Vector with associated FE space.
const SparseMatrix * GetConformingProlongation() const
The returned SparseMatrix is owned by the FiniteElementSpace.
Data type for scaled Jacobi-type smoother of sparse matrix.
double GetSurfaceFittingWeight()
Get the surface fitting weight.
ParMesh * GetParMesh() const
void UpdateDiscreteTC(const TMOP_Integrator &ti, const Vector &x_new) const
double surf_fit_err_avg_prvs
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
double surf_fit_max_threshold
void SetSize(int s)
Resize the vector to size s.
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.
double MinDetJpr_2D(const FiniteElementSpace *, const Vector &) const
Base abstract class for first order time dependent operators.
bool summary
A summary of the solver process will be reported after the last iteration to mfem::out.
bool first_and_last
Information about the first and last iteration will be printed to mfem::out.
Pointer to an Operator of a specified type.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
ParFiniteElementSpace * pfes
Data type dense matrix using column-major storage.
void GetSurfaceFittingErrors(double &err_avg, double &err_max)
int Size() const
Returns the size of the vector.
void Init(TimeDependentOperator &f_) override
Associate a TimeDependentOperator with the ODE solver.
const IntegrationRule & GetIntegrationRule(const FiniteElement &el) const
int GetNE() const
Returns number of elements.
bool IsSurfaceFittingEnabled()
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
Abstract parallel finite element space.
void vis_tmop_metric_s(int order, TMOP_QualityMetric &qm, const TargetConstructor &tc, Mesh &mesh, char *title, int position)
void UpdateSurfaceFittingWeight(double factor)
Update the surface fitting weight as surf_fit_coeff *= factor;.
void UpdateGradientTargetSpecification(const Vector &x, double dx, bool use_flag=false)
bool UsesTensorBasis(const FiniteElementSpace &fes)
T Min() const
Find the minimal element in the array, using the comparison operator < for class T.
void add(const Vector &v1, const Vector &v2, Vector &v)
const DenseMatrix & GetGeomToPerfGeomJac(int GeomType) const
double Norm(const Vector &x) const
void UpdateTargetSpecification(const Vector &new_x, bool use_flag=false)
virtual void ComputeAtNewPosition(const Vector &new_nodes, Vector &new_field)
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
int GetNE() const
Returns number of elements in the mesh.
Abstract class for local mesh quality metrics in the target-matrix optimization paradigm (TMOP) by P...
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
void UpdateAfterMeshPositionChange(const Vector &new_x)
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
double f(const Vector &xvec)
double GetElementSize(ElementTransformation *T, int type=0)
void GetSurfaceFittingWeight(Array< double > &weights) const
Get the surface fitting weight for all the TMOP integrators.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
int Append(const T &el)
Append element 'el' to array, resize if necessary.
Mesh * GetMesh() const
Returns the mesh.
Jacobi smoothing for a given bilinear form (no matrix necessary).
static MemoryType GetDeviceMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
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...
void SetMaxIter(int max_it)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
void Setup(Mesh &m, const double bb_t=0.1, const double newt_tol=1.0e-12, const int npt_max=256)
Performs a single remap advection step in serial.
void UpdateSurfaceFittingWeight(double factor) const
Update surface fitting weight as surf_fit_weight *= factor.
Parallel smoothers in hypre.
FiniteElementSpace * FESpace()
Wrapper for hypre's parallel vector class.
double Min() const
Returns the minimal element of the vector.
virtual void ProcessNewState(const Vector &x) const
double * Data() const
Returns the matrix data array.
void SetAbsTol(double atol)
PrintLevel print_options
Output behavior for the iterative solver.
void SetRelTol(double rtol)
void UpdateHessianTargetSpecification(const Vector &x, double dx, bool use_flag=false)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
void subtract(const Vector &x, const Vector &y, Vector &z)
MemoryType
Memory types supported by MFEM.
Performs a single remap advection step in parallel.
bool update_surf_fit_coeff
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
DiscreteAdaptTC * GetDiscreteAdaptTC() const
void ResetUpdateFlags()
Used in combination with the Update methods to avoid extra computations.
void SaveAsOne(const char *fname, int precision=16) const
virtual void ComputeAtNewPosition(const Vector &new_nodes, Vector &new_field)
void ComputeFDh(const Vector &x, const FiniteElementSpace &fes)
Determines the perturbation, h, for FD-based approximation.
double Max() const
Returns the maximal element of the vector.
double MinDetJpr_3D(const FiniteElementSpace *, const Vector &) const
virtual void Print(std::ostream &os=mfem::out) const
FDualNumber< tbase > sqrt(const FDualNumber< tbase > &f)
sqrt([dual number])
void vel(const Vector &x, double t, Vector &u)
virtual void SetInitialField(const Vector &init_nodes, const Vector &init_field)
VectorGridFunctionCoefficient u_coeff
virtual void Mult(const Vector &x, Vector &y) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x...
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
virtual void GetSurfaceFittingError(double &err_avg, double &err_max) const
SerialAdvectorCGOper(const Vector &x_start, GridFunction &vel, FiniteElementSpace &fes, AssemblyLevel al=AssemblyLevel::LEGACY)
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
virtual void SetSpace(FiniteElementSpace *f)
Associate a new FiniteElementSpace with the GridFunction.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
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 SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
ParAdvectorCGOper(const Vector &x_start, GridFunction &vel, ParFiniteElementSpace &pfes, AssemblyLevel al=AssemblyLevel::LEGACY, MemoryType mt=MemoryType::DEFAULT)
void MultAtB(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &AtB)
Multiply the transpose of a matrix A with a matrix B: At*B.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points...
const FiniteElementCollection * FEColl() const
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
void GetNodes(Vector &node_coord) const
virtual double ComputeScalingFactor(const Vector &x, const Vector &b) const
void PrintAsOne(std::ostream &out=mfem::out) const
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
void Step(Vector &x, double &t, double &dt) override
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
void DeleteGeometricFactors()
Destroy all GeometricFactors stored by the Mesh.
bool iterations
Detailed information about each iteration will be reported to mfem::out.
double u(const Vector &xvec)
void SetNodes(const Vector &node_coord)
Class for parallel grid function.
Base class representing target-matrix construction algorithms for mesh optimization via the target-ma...
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
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...
Class for parallel meshes.
double ComputeMinDet(const Vector &x_loc, const FiniteElementSpace &fes) const
const Array< TMOP_Integrator * > & GetTMOPIntegrators() const
virtual double * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
void Reset(OpType *A, bool own_A=true)
Reset the OperatorHandle to the given OpType pointer, A.
virtual void SetInitialField(const Vector &init_nodes, const Vector &init_field)
Arbitrary order "L2-conforming" discontinuous finite elements.
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.