27PetscErrorCode
SnesRhs(SNES snes, Vec x, Vec f,
void *ctx) {
32 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
33 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
36 CHKERR VecAssemblyBegin(f);
38 MPI_Comm comm = PetscObjectComm((PetscObject)f);
39 PetscSynchronizedPrintf(comm,
"SNES Verify x\n");
48 auto zero_ghost_vec = [](Vec
g) {
56 for (
int i = 0;
i != s; ++
i)
59 CHKERR VecGhostRestoreLocalForm(
g, &
l);
65 auto cache_ptr = boost::make_shared<CacheTuple>();
69 auto set = [&](
auto &fe) {
76 fe.cacheWeakPtr = cache_ptr;
79 auto unset = [&](
auto &fe) {
98 snes_ctx->
problemName, lit.first, *lit.second,
nullptr, snes_ctx->
bH,
103 CHKERR VecAssemblyBegin(f);
105 MPI_Comm comm = PetscObjectComm((PetscObject)f);
106 PetscSynchronizedPrintf(comm,
"SNES Verify f FE < %s >\n",
127 CHKERR VecGhostUpdateBegin(f, ADD_VALUES, SCATTER_REVERSE);
128 CHKERR VecGhostUpdateEnd(f, ADD_VALUES, SCATTER_REVERSE);
129 CHKERR VecAssemblyBegin(f);
136PetscErrorCode
SnesMat(SNES snes, Vec x, Mat
A, Mat
B,
void *ctx) {
145 auto cache_ptr = boost::make_shared<CacheTuple>();
149 auto set = [&](
auto &fe) {
157 fe.cacheWeakPtr = cache_ptr;
160 auto unset = [&](
auto &fe) {
167 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
168 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
186 snes_ctx->
problemName, lit.first, *(lit.second),
nullptr, snes_ctx->
bH,
213 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
221 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
229 auto &m_field = snes_ctx->
mField;
231 auto fields_ptr = m_field.get_fields();
234 std::vector<double> lnorms(fields_ptr->size(), 0),
235 norms(fields_ptr->size(), 0);
238 CHKERR SNESGetFunction(snes, &res, NULL, NULL);
241 CHKERR VecGetArrayRead(res, &r);
244 for (
auto fi : *fields_ptr) {
247 const auto hi = dofs->get<
Unique_mi_tag>().upper_bound(hi_uid);
248 for (
auto lo = dofs->get<
Unique_mi_tag>().lower_bound(lo_uid); lo != hi;
250 const DofIdx loc_idx = (*lo)->getPetscLocalDofIdx();
251 if (loc_idx >= 0 && loc_idx < problem_ptr->nbLocDofsRow) {
252 lnorms[f] += PetscRealPart(PetscSqr(r[loc_idx]));
258 CHKERR VecRestoreArrayRead(res, &r);
260 MPIU_Allreduce(&*lnorms.begin(), &*norms.begin(), lnorms.size(), MPIU_REAL,
261 MPIU_SUM, PetscObjectComm((PetscObject)snes));
265 CHKERR PetscObjectGetTabLevel((PetscObject)snes, &tl);
266 for (
auto t = 0;
t != tl; ++
t)
268 s << its <<
" Function norm " << boost::format(
"%14.12e") % (
double)fgnorm
272 for (
auto fi : *fields_ptr) {
275 s << boost::format(
"%14.12e") % (
double)PetscSqrtReal(norms[f]);
281 MOFEM_LOG(
"SNES_WORLD", Sev::inform) << s.str();
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
#define MOFEM_LOG(channel, severity)
Log.
virtual MoFEMErrorCode problem_basic_method_postProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MoFEMErrorCode loop_finite_elements(const std::string problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'l', 3 > l
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
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.
MoFEMErrorCode MoFEMSNESMonitorFields(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *snes_ctx)
Sens monitor printing residual field by field.
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.
MoFEMErrorCode SnesMoFEMSetAssemblyType(SNES snes, MatAssemblyType type)
Set assembly type at the end of SnesMat.
MoFEMErrorCode SnesMoFEMSetBehavior(SNES snes, MoFEMTypes bh)
Set behavior if finite element in sequence does not exist.
constexpr double t
plate stiffness
virtual MoFEMErrorCode cache_problem_entities(const std::string prb_name, CacheTupleWeakPtr cache_ptr)=0
Cache variables.
virtual MoFEMErrorCode problem_basic_method_preProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
static constexpr Switches CtxSetA
static constexpr Switches CtxSetX
static constexpr Switches CtxSetNone
static constexpr Switches CtxSetF
static constexpr Switches CtxSetB
keeps basic data about problem
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
Interface for nonlinear (SNES) solver.
PetscLogEvent MOFEM_EVENT_SnesMat
Log events to assemble tangent matrix.
BasicMethodsSequence preProcess_Rhs
Sequence of methods run before residual is assembled.
BasicMethodsSequence postProcess_Mat
MoFEMTypes bH
If set to MF_EXIST check if element exist, default MF_EXIST.
BasicMethodsSequence postProcess_Rhs
Sequence of methods run after residual is assembled.
MoFEMErrorCode copyLoops(const SnesCtx &snes_ctx)
Copy sequences from other SNES contex.
MatAssemblyType typeOfAssembly
type of assembly at the end
MoFEMErrorCode clearLoops()
Clear loops.
BasicMethodsSequence preProcess_Mat
bool vErify
If true verify vector.
FEMethodsSequence loops_to_do_Mat
std::string problemName
problem name
FEMethodsSequence loops_to_do_Rhs
boost::movelib::unique_ptr< bool > matAssembleSwitch
MoFEM::Interface & mField
database Interface
boost::movelib::unique_ptr< bool > vecAssembleSwitch
PetscLogEvent MOFEM_EVENT_SnesRhs
Log events to assemble residual.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.