85 {
86
87
89
90 try {
91
92
93 moab::Core moab_core;
94 moab::Interface &moab = moab_core;
95
96
99
100
101 DMType dm_name = "DMMOFEM";
103
104
105 auto core_log = logging::core::get();
106 core_log->add_sink(
110
111
113
114
116
118
123
124
131
132
134
135
136
139 "T", 0, 1);
140
148
160
163
164 auto shell_data =
166
168
169 {{simple->getDomainFEName(),
170
171 {{"V", "V"},
172 {"T", "T"},
173 {"S", "S"},
174 {"O", "O"},
175 {"V", "T"},
176 {"T", "V"},
177 {"S", "T"},
178 {"T", "S"},
179 {"T", "O"},
180 {"O", "T"},
181 {"S", "O"},
182 {"O", "S"}
183
184 }}}
185
186 )
187
188 );
189
190 auto [mat, block_data_ptr] = shell_data;
192
193 std::vector<std::string> fields{"T", "S", "O"};
194
196
198
199 {schur_dm, block_dm}, block_data_ptr,
200
201 fields, {nullptr, nullptr, nullptr}, true
202
203 )
204
205 );
206
211 using OpMassBlockPreconditionerAssemble =
213 BiLinearForm<GAUSS>::OpMass<1,
FIELD_DIM>;
214
215
217
218
222
224 [](int, int, int o) { return 2 * o; });
225 auto &pip_lhs = pip_mng->getOpDomainLhsPipeline();
226
227 pip_lhs.push_back(new OpMassPETSCAssemble("V", "V"));
228
229 pip_lhs.push_back(new OpMassPETSCAssemble("V", "T"));
230 pip_lhs.push_back(new OpMassPETSCAssemble("T", "V"));
231 pip_lhs.push_back(new OpMassPETSCAssemble("S", "S", close_zero));
232 pip_lhs.push_back(new OpMassPETSCAssemble("S", "T", beta));
233 pip_lhs.push_back(new OpMassPETSCAssemble("T", "S", beta));
234 pip_lhs.push_back(new OpMassPETSCAssemble("O", "O", close_zero));
235 pip_lhs.push_back(new OpMassPETSCAssemble("T", "O", beta));
236 pip_lhs.push_back(new OpMassPETSCAssemble("O", "T", beta));
237 pip_lhs.push_back(new OpMassPETSCAssemble("S", "O", gamma));
238 pip_lhs.push_back(new OpMassPETSCAssemble("O", "S", gamma));
239
241 pip_lhs.push_back(new OpMassBlockAssemble("V", "V"));
242
243 pip_lhs.push_back(new OpMassBlockAssemble("V", "T"));
244 pip_lhs.push_back(new OpMassBlockAssemble("T", "V"));
245 pip_lhs.push_back(new OpMassBlockAssemble("S", "S", close_zero));
246 pip_lhs.push_back(new OpMassBlockAssemble("S", "T", beta));
247 pip_lhs.push_back(new OpMassBlockAssemble("T", "S", beta));
248 pip_lhs.push_back(new OpMassBlockAssemble("O", "O", close_zero));
249 pip_lhs.push_back(new OpMassBlockAssemble("T", "O", beta));
250 pip_lhs.push_back(new OpMassBlockAssemble("O", "T", beta));
251 pip_lhs.push_back(new OpMassBlockAssemble("S", "O", gamma));
252 pip_lhs.push_back(new OpMassBlockAssemble("O", "S", gamma));
253 pip_lhs.push_back(new OpMassBlockPreconditionerAssemble("T", "T"));
254
255 auto schur_is =
getDMSubData(schur_dm)->getSmartRowIs();
257
259
260 fields, {nullptr, nullptr, nullptr}, ao_up, S, true, true)
261
262 );
263
264 {
267 BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
268 MOFEM_LOG(
"Timeline", Sev::inform) <<
"Assemble start";
270 simple->getDomainFEName(),
271 pip_mng->getDomainLhsFE());
272 MOFEM_LOG(
"Timeline", Sev::inform) <<
"Assemble end";
273 }
274 {
277 BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
278 MOFEM_LOG(
"Timeline", Sev::inform) <<
"Mat assemble start";
281 MOFEM_LOG(
"Timeline", Sev::inform) <<
"Mat assemble end";
282 }
283
284 auto get_random_vector = [&](auto dm) {
286 PetscRandom rctx;
287 PetscRandomCreate(PETSC_COMM_WORLD, &rctx);
289 PetscRandomDestroy(&rctx);
291 };
292 auto v = get_random_vector(
simple->getDM());
293
296
297 auto test = [](auto msg, auto y, double norm0) {
299
302
303 PetscReal norm;
304 CHKERR VecNorm(y, NORM_2, &norm);
305 norm = norm / norm0;
308 << msg << ": norm of difference: " << norm;
309 if (norm >
eps || std::isnan(norm) || std::isinf(norm)) {
310 SETERRQ(PETSC_COMM_WORLD, 1, "norm of difference is too big");
311 }
313 };
314
315 std::vector<int> zero_rows_and_cols = {
316 0, 1, 10, 20,
317 500};
319 &*zero_rows_and_cols.begin(), 1, PETSC_NULL,
320 PETSC_NULL);
322 &*zero_rows_and_cols.begin(), 1, PETSC_NULL,
323 PETSC_NULL);
324
325 {
328 BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
330 << "MatMult(petsc_mat, v, y_petsc) star";
333 << "MatMult(petsc_mat, v, y_petsc) end";
334 }
335 double nrm0;
336 CHKERR VecNorm(y_petsc, NORM_2, &nrm0);
337
338 {
341 BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
343 << "MatMult(block_mat, v, y_block) star";
346 << "MatMult(block_mat, v, y_block) end";
347 }
348
349 CHKERR VecAXPY(y_petsc, -1.0, y_block);
350 CHKERR test(
"mult", y_petsc, nrm0);
351
354
359 CHKERR VecAXPY(y_petsc, -1.0, y_block);
360
361 CHKERR test(
"mult add", y_petsc, nrm0);
365
366 CHKERR MatMult(nested_mat,
v, y_nested);
367 CHKERR VecAXPY(y_petsc, -1.0, y_nested);
368
369 CHKERR test(
"mult nested", y_petsc, nrm0);
370
372 auto diag_mat = std::get<0>(*nested_data_ptr)[3];
373 auto diag_block_x = get_random_vector(block_dm);
376 CHKERR MatMult(diag_mat, diag_block_x, diag_block_f);
377
378
379
380
381
382 CHKERR DMSetMatType(block_dm, MATSHELL);
384
385 CHKERR DMKSPSetComputeOperators(
386 block_dm,
387 [](KSP, Mat, Mat, void *) {
388 MOFEM_LOG(
"WORLD", Sev::inform) <<
"empty operator";
389 return 0;
390 },
391 nullptr);
392
394 CHKERR KSPSetDM(ksp, block_dm);
395 CHKERR KSPSetFromOptions(ksp);
396
397
398 auto get_pc = [](auto ksp) {
399 PC pc_raw;
400 CHKERR KSPGetPC(ksp, &pc_raw);
402 };
405
406 CHKERR VecZeroEntries(block_solved_x);
407 CHKERR KSPSolve(ksp, diag_block_f, block_solved_x);
408
410 CHKERR MatMult(diag_mat, block_solved_x, diag_block_f_test);
411 CHKERR VecAXPY(diag_block_f_test, -1.0, diag_block_f);
412 CHKERR test(
"diag solve", diag_block_f_test, nrm0);
413
416 }
417
420 }
422
423
425
426 return 0;
427}
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
void simple(double P1[], double P2[], double P3[], double c[], const int N)
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base nme:nme847.
@ L2
field with C-1 continuity
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
auto createDMVector(DM dm)
Get smart vector from DM.
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
auto createDMMatrix(DM dm)
Get smart matrix from DM.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
const double v
phase velocity of light in medium (cm/ns)
auto createKSP(MPI_Comm comm)
OpSchurAssembleBase * createOpSchurAssembleEnd(std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range > > field_ents, SmartPetscObj< AO > ao, SmartPetscObj< Mat > schur, bool sym_schur, bool symm_op)
Construct a new Op Schur Assemble End object.
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
MoFEMErrorCode schurSwitchPreconditioner(boost::shared_ptr< BlockStructure > block_mat_data)
Switch preconditioner.
MoFEMErrorCode setSchurA00MatSolvePC(SmartPetscObj< PC > pc)
Set PC for A00 block.
std::pair< SmartPetscObj< Mat >, boost::shared_ptr< NestSchurData > > createSchurNestedMatrix(boost::shared_ptr< NestSchurData > schur_net_data_ptr)
Create a Mat Diag Blocks object.
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
auto getDMSubData(DM dm)
Get sub problem data structure.
MoFEMErrorCode DMMoFEMSetBlocMatData(DM dm, boost::shared_ptr< BlockStructure >)
Set data for block mat.
boost::shared_ptr< BlockStructure > createBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec)
Create a Mat Diag Blocks object.
boost::shared_ptr< NestSchurData > createSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< BlockStructure > block_mat_data_ptr, std::vector< std::string > fields_names, std::vector< boost::shared_ptr< Range > > field_ents, bool add_preconditioner_block)
Get the Schur Nest Mat Array object.
auto createAOMappingIS(IS isapp, IS ispetsc)
Creates an application mapping using two index sets.
MoFEMErrorCode schurSaveBlockMesh(boost::shared_ptr< BlockStructure > block_mat_data, std::string filename)
Save block matrix as a mesh.
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
OpSchurAssembleBase * createOpSchurAssembleBegin()
SmartPetscObj< Mat > block_mat
SmartPetscObj< Mat > petsc_mat
Simple interface for fast problem set-up.
MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true, bool is_distributed_mesh=true)
Remove DOFs from problem.
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
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.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
PipelineManager interface.
MoFEMErrorCode setDomainLhsIntegrationRule(RuleHookFun rule)
Simple interface for fast problem set-up.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.