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());
127 v_max = std::sqrt(v_max);
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 const bool untangling = (min_detT_in <= 0.0) ?
true :
false;
405 const double untangle_factor = 1.5;
416 bool x_out_ok =
false;
417 double scale = 1.0, energy_out = 0.0, min_detT_out;
418 const double norm_in =
Norm(
r);
420 const double detJ_factor = (
solver_type == 1) ? 0.25 : 0.5;
423 for (
int i = 0; i < 12; i++)
426 add(x, -scale,
c, x_out);
430 if (!cP) { x_out_loc = x_out; }
431 else { cP->
Mult(x_out, x_out_loc); }
442 if (untangling ==
false && min_detT_out < 0.0)
446 {
mfem::out <<
"Scale = " << scale <<
" Neg det(J) found.\n"; }
447 scale *= detJ_factor;
continue;
449 if (untangling ==
true && min_detT_out < *
min_det_ptr)
453 {
mfem::out <<
"Scale = " << scale <<
" Neg det(J) decreased.\n"; }
454 scale *= detJ_factor;
continue;
460 if (untangling) { x_out_ok =
true;
break; }
475 if (energy_out > energy_in + 0.2*fabs(energy_in) ||
476 std::isnan(energy_out) != 0)
480 mfem::out <<
"Scale = " << scale <<
" Increasing energy: "
481 << energy_in <<
" --> " << energy_out <<
'\n';
483 scale *= 0.5;
continue;
487 oper->
Mult(x_out,
r);
488 if (have_b) {
r -=
b; }
489 double norm_out =
Norm(
r);
491 if (norm_out > 1.2*norm_in)
495 mfem::out <<
"Scale = " << scale <<
" Norm increased: "
496 << norm_in <<
" --> " << norm_out <<
'\n';
498 scale *= 0.5;
continue;
500 else { x_out_ok =
true;
break; }
506 if (min_detT_out > 0.0)
510 {
mfem::out <<
"The mesh has been untangled at the used points!\n"; }
512 else { *
min_det_ptr = untangle_factor * min_detT_out; }
520 << min_detT_in <<
" -> " << min_detT_out
521 <<
" with " << scale <<
" scaling.\n";
526 << energy_in <<
" --> " << energy_out <<
" or "
527 << (energy_in - energy_out) / energy_in * 100.0
528 <<
"% with " << scale <<
" scaling.\n";
532 if (x_out_ok ==
false) { scale = 0.0; }
546 for (
int i = 0; i < integs.
Size(); i++)
558 for (
int j = 0; j < ati.
Size(); j++)
560 dtc = ati[j]->GetDiscreteAdaptTC();
574 for (
int i = 0; i < integs.
Size(); i++)
587 for (
int j = 0; j < ati.
Size(); j++)
589 ati[j]->UpdateAfterMeshChange(x_loc);
590 ati[j]->ComputeFDh(x_loc, *pfesc);
611 for (
int i = 0; i < integs.
Size(); i++)
624 for (
int j = 0; j < ati.
Size(); j++)
626 ati[j]->UpdateAfterMeshChange(x_loc);
627 ati[j]->ComputeFDh(x_loc, *fesc);
636 const Vector &x_new)
const
638 const bool update_flag =
true;
662 for (
int i = 0; i < NE; i++)
673 for (
int j = 0; j < nsp; j++)
677 min_detJ = std::min(min_detJ, Jpr.
Det());
686 double min_detT_all = min_detJ;
691 MPI_Allreduce(&min_detJ, &min_detT_all, 1, MPI_DOUBLE, MPI_MIN,
692 p_nlf->ParFESpace()->GetComm());
697 min_detT_all /= Wideal.
Det();
707 char *title,
int position)
716 sock.
open(
"localhost", 19916);
717 sock <<
"solution\n";
723 sock <<
"window_title '"<< title <<
"'\n"
724 <<
"window_geometry "
725 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
735 char *title,
int position)
742 sock <<
"solution\n";
746 sock <<
"window_title '"<< title <<
"'\n"
747 <<
"window_geometry "
748 << 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().
virtual void Print(std::ostream &out=mfem::out) const
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.
void UpdateAfterMeshChange(const Vector &new_x)
const SparseMatrix * GetConformingProlongation() const
The returned SparseMatrix is owned by the FiniteElementSpace.
Data type for scaled Jacobi-type smoother of sparse matrix.
ParMesh * GetParMesh() const
void UpdateDiscreteTC(const TMOP_Integrator &ti, const Vector &x_new) const
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.
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.
void GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
double MinDetJpr_2D(const FiniteElementSpace *, const Vector &) const
Base abstract class for first order time dependent operators.
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.
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.
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 UpdateGradientTargetSpecification(const Vector &x, double dx, bool use_flag=false)
bool UsesTensorBasis(const FiniteElementSpace &fes)
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 SetPrintLevel(int print_lvl)
double f(const Vector &xvec)
double GetElementSize(ElementTransformation *T, int type=0)
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
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)
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.
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
This method can be overloaded in derived classes to perform computations that need knowledge of the n...
double * Data() const
Returns the matrix data array.
void SetAbsTol(double atol)
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.
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
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...
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
This method can be overloaded in derived classes to implement line search algorithms.
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.
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.