51int main(
int argc,
char *argv[])
53 const char *mesh_file =
"../../data/star.vtk";
54 int ser_ref_levels = 1;
56 bool visualization =
false;
57 real_t newton_rel_tol = 1e-4;
58 real_t newton_abs_tol = 1e-6;
63 args.
AddOption(&mesh_file,
"-m",
"--mesh",
"Mesh file to use.");
67 "Number of times to refine the mesh uniformly in serial.");
71 "Order (degree) of the finite elements.");
77 "Enable or disable GLVis visualization.");
80 "--relative-tolerance",
81 "Relative tolerance for the Newton solve.");
84 "--absolute-tolerance",
85 "Absolute tolerance for the Newton solve.");
88 "--newton-iterations",
89 "Maximum iterations for the Newton solve.");
107 for (
int lev = 0; lev < ser_ref_levels; lev++)
188 nf->
Mult(solbv,resbv);
189 std::cout<<
"Norm residual="<<resbv.
Norml2()<<std::endl;
193 std::cout<<
"energy ="<< energy<<std::endl;
204 std::cout<<
"Objective ="<<obj<<std::endl;
210 ob->
Mult(solbv, adjrhs);
272 for (
int l = 0; l < 10; l++)
278 add(prmbv,prtbv,tmpbv);
285 real_t ld=(lQoI-gQoI)/lsc;
286 std::cout <<
"dx=" << lsc <<
" FD gradient=" << ld/nd
287 <<
" adjoint gradient=" << td
288 <<
" err=" << std::fabs(ld/nd-td) << std::endl;
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
A class to handle Block systems in a matrix-free implementation.
Operator & GetBlock(int i, int j)
Return a reference to block i,j.
A class to handle Vectors in a block fashion.
void Update(real_t *data, const Array< int > &bOffsets)
Update method.
Vector & GetBlock(int i)
Get the i-th vector in the block.
A coefficient that is constant across space and time.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual void Mult(const Vector &b, Vector &x) const
Iterative solution of the linear system using the GMRES method.
Class for grid function - Vector with associated FE space.
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
Arbitrary order H1-conforming (continuous) finite elements.
virtual void SetOperator(const Operator &op) override
Also calls SetOperator for the preconditioner if there is one.
void SetRelTol(real_t rtol)
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)
Arbitrary order "L2-conforming" discontinuous finite elements.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
int Dimension() const
Dimension of the reference space used within the elements.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Newton's method for solving F(x)=b for a given operator F.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
virtual void SetSolver(Solver &solver)
Set the linear solver for inverting the Jacobian.
virtual void Mult(const Vector &b, Vector &x) const
Solve the nonlinear system with right-hand side b.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
bool Good() const
Return true if the command line options were parsed successfully.
Helper class for ParaView visualization data.
void SetLevelsOfDetail(int levels_of_detail_)
virtual void Save() override
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
void Randomize(int seed=0)
Set random values in the vector.
real_t Norml2() const
Returns the l2 norm of the vector.
void add(const Vector &v1, const Vector &v2, Vector &v)
real_t InnerProduct(HypreParVector *x, HypreParVector *y)