27PetscErrorCode
SnesRhs(SNES snes, Vec x, Vec f,
void *ctx) {
33 CHKERR SNESGetSolutionUpdate(snes, &dx);
34 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
35 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
38 CHKERR VecAssemblyBegin(f);
40 MPI_Comm comm = PetscObjectComm((PetscObject)f);
41 PetscSynchronizedPrintf(comm,
"SNES Verify x\n");
50 auto zero_ghost_vec = [](Vec
g) {
58 for (
int i = 0;
i != s; ++
i)
61 CHKERR VecGhostRestoreLocalForm(
g, &
l);
67 auto cache_ptr = boost::make_shared<CacheTuple>();
71 auto set = [&](
auto &fe) {
80 CHKERR SNESGetKSP(snes, &fe.ksp);
82 fe.cacheWeakPtr = cache_ptr;
85 auto unset = [&](
auto &fe) {
104 snes_ctx->
problemName, lit.first, *lit.second,
nullptr, snes_ctx->
bH,
109 CHKERR VecAssemblyBegin(f);
111 MPI_Comm comm = PetscObjectComm((PetscObject)f);
112 PetscSynchronizedPrintf(comm,
"SNES Verify f FE < %s >\n",
133 CHKERR VecGhostUpdateBegin(f, ADD_VALUES, SCATTER_REVERSE);
134 CHKERR VecGhostUpdateEnd(f, ADD_VALUES, SCATTER_REVERSE);
135 CHKERR VecAssemblyBegin(f);
142PetscErrorCode
SnesMat(SNES snes, Vec x, Mat
A, Mat
B,
void *ctx) {
151 auto cache_ptr = boost::make_shared<CacheTuple>();
155 CHKERR SNESGetSolutionUpdate(snes, &dx);
157 auto set = [&](
auto &fe) {
168 CHKERR SNESGetKSP(snes, &fe.ksp);
170 fe.cacheWeakPtr = cache_ptr;
173 auto unset = [&](
auto &fe) {
180 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
181 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
199 snes_ctx->
problemName, lit.first, *(lit.second),
nullptr, snes_ctx->
bH,
226 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
234 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
242 auto &m_field = snes_ctx->
mField;
244 auto fields_ptr = m_field.get_fields();
247 std::vector<double> lnorms(fields_ptr->size(), 0),
248 norms(fields_ptr->size(), 0);
251 CHKERR SNESGetFunction(snes, &res, NULL, NULL);
254 CHKERR VecGetArrayRead(res, &r);
257 for (
auto fi : *fields_ptr) {
260 const auto hi = dofs->get<
Unique_mi_tag>().upper_bound(hi_uid);
261 for (
auto lo = dofs->get<
Unique_mi_tag>().lower_bound(lo_uid); lo != hi;
263 const DofIdx loc_idx = (*lo)->getPetscLocalDofIdx();
264 if (loc_idx >= 0 && loc_idx < problem_ptr->nbLocDofsRow) {
265 lnorms[f] += PetscRealPart(PetscSqr(r[loc_idx]));
271 CHKERR VecRestoreArrayRead(res, &r);
273 MPIU_Allreduce(&*lnorms.begin(), &*norms.begin(), lnorms.size(), MPIU_REAL,
274 MPIU_SUM, PetscObjectComm((PetscObject)snes));
278 CHKERR PetscObjectGetTabLevel((PetscObject)snes, &tl);
279 for (
auto t = 0;
t != tl; ++
t)
281 s << its <<
" Function norm " << boost::format(
"%14.12e") % (
double)fgnorm
285 for (
auto fi : *fields_ptr) {
288 s << boost::format(
"%14.12e") % (
double)PetscSqrtReal(norms[f]);
294 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 CtxSetDX
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.
MatAssemblyType typeOfAssembly
type of assembly at the end
MoFEMErrorCode copyLoops(const SnesCtx &snes_ctx)
Copy sequences from other SNES contex.
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
MoFEMErrorCode clearLoops()
Clear loops.
PetscLogEvent MOFEM_EVENT_SnesRhs
Log events to assemble residual.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.