18                                 {
   19 
   20  
   22 
   23  
   24  moab::Core mb_instance;              
   25  moab::Interface &moab = mb_instance; 
   26 
   27  try {
   28    
   31 
   32    PetscBool ale = PETSC_FALSE;
   34    PetscBool test_jacobian = PETSC_FALSE;
   36                               PETSC_NULLPTR);
   37 
   39 
   41 
   47 
   48    if (ale == PETSC_TRUE) {
   51    }
   52 
   54 
   55    
   56    DM dm;
   58 
   59    
   60    {
   63      
   64    }
   65 
   66    
   67    if (ale == PETSC_TRUE) {
   70      
   71    }
   72 
   73    boost::shared_ptr<ForcesAndSourcesCore> fe_lhs_ptr(
   75    boost::shared_ptr<ForcesAndSourcesCore> fe_rhs_ptr(
   79    };
   80    fe_lhs_ptr->getRuleHook = 
VolRule();
 
   81    fe_rhs_ptr->getRuleHook = 
VolRule();
 
   82 
   84                                  nullptr, nullptr);
   86                                  nullptr, nullptr);
   87 
   89    boost::shared_ptr<map<int, BlockData>> block_sets_ptr =
   90        boost::make_shared<map<int, BlockData>>();
   91    (*block_sets_ptr)[0].
iD = 0;
 
   92    (*block_sets_ptr)[0].E = 1;
   93    (*block_sets_ptr)[0].PoissonRatio = 0.25;
   96 
   97    CHKERR HookeElement::setOperators(fe_lhs_ptr, fe_rhs_ptr, block_sets_ptr,
 
   98                                      "x", "X", ale, false);
   99 
  101    CHKERR DMCreateGlobalVector(dm, &x);
 
  102    CHKERR VecDuplicate(x, &f);
 
  104 
  105    
  106    
  107    
  108    
  109    
  110    
  111 
  113    CHKERR DMCreateMatrix(dm, &A);
 
  114    CHKERR MatDuplicate(A, MAT_DO_NOT_COPY_VALUES, &fdA);
 
  115 
  116    if (test_jacobian == PETSC_TRUE) {
  117      char testing_options[] =
  118          "-snes_test_jacobian -snes_test_jacobian_display "
  119          "-snes_no_convergence_test -snes_atol 0 -snes_rtol 0 -snes_max_it 1 "
  120          "-pc_type none";
  121      CHKERR PetscOptionsInsertString(NULL, testing_options);
 
  122    } else {
  123      char testing_options[] = "-snes_no_convergence_test -snes_atol 0 "
  124                               "-snes_rtol 0 -snes_max_it 1 -pc_type none";
  125      CHKERR PetscOptionsInsertString(NULL, testing_options);
 
  126    }
  127 
  128    SNES snes;
  129    CHKERR SNESCreate(PETSC_COMM_WORLD, &snes);
 
  134    CHKERR SNESSetFromOptions(snes);
 
  135 
  136    CHKERR SNESSolve(snes, NULL, x);
 
  137 
  138    if (test_jacobian == PETSC_FALSE) {
  139      double nrm_A0;
  140      CHKERR MatNorm(A, NORM_INFINITY, &nrm_A0);
 
  141 
  142      char testing_options_fd[] = "-snes_fd";
  143      CHKERR PetscOptionsInsertString(NULL, testing_options_fd);
 
  144 
  147      CHKERR SNESSetFromOptions(snes);
 
  148 
  149      CHKERR SNESSolve(snes, NULL, x);
 
  150      CHKERR MatAXPY(A, -1, fdA, SUBSET_NONZERO_PATTERN);
 
  151 
  152      double nrm_A;
  153      CHKERR MatNorm(A, NORM_INFINITY, &nrm_A);
 
  154      PetscPrintf(PETSC_COMM_WORLD, "Matrix norms %3.4e %3.4e\n", nrm_A,
  155                  nrm_A / nrm_A0);
  156      nrm_A /= nrm_A0;
  157 
  158      const double tol = 1e-5;
 
  161                "Difference between hand-calculated tangent matrix and finite "
  162                "difference matrix is too big");
  163      }
  164    }
  165 
  170    CHKERR SNESDestroy(&snes);
 
  171 
  172    
  174  }
  176 
  177  
  179 
  180  return 0;
  181}
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
@ MOFEM_ATOM_TEST_INVALID
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES residual evaluation function
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES Jacobian evaluation function
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMMoFEMGetSnesCtx(DM dm, MoFEM::SnesCtx **snes_ctx)
get MoFEM::SnesCtx data structure
virtual MoFEMErrorCode get_finite_element_entities_by_dimension(const std::string name, int dim, Range &ents) const =0
get entities in the finite element by dimension
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
const FTensor::Tensor2< T, Dim, Dim > Vec
PetscErrorCode SnesMat(SNES snes, Vec x, Mat A, Mat B, void *ctx)
This is MoFEM implementation for the left hand side (tangent matrix) evaluation in SNES solver.
PetscErrorCode SnesRhs(SNES snes, Vec x, Vec f, void *ctx)
This is MoFEM implementation for the right hand side (residual vector) evaluation in SNES solver.
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Projection of edge entities with one mid-node on hierarchical basis.
Simple interface for fast problem set-up.
MoFEMErrorCode addDomainField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
MoFEMErrorCode getOptions()
get options
MoFEMErrorCode getDM(DM *dm)
Get DM.
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
const std::string getDomainFEName() const
Get the Domain FE Name.
Interface for nonlinear (SNES) solver.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Volume finite element base.
data for calculation heat conductivity and heat capacity elements
Set integration rule to volume elements.
int operator()(int, int, int) const