10 static char help[] =
"...\n\n";
20 const double D = 2e-3;
24 const double u0 = 0.1;
49 :
OpEle(
"u",
"u",
OpEle::OPROWCOL), commonData(data) {
53 EntityType col_type,
EntData &row_data,
56 const int nb_row_dofs = row_data.
getIndices().size();
57 const int nb_col_dofs = col_data.
getIndices().size();
58 if (nb_row_dofs && nb_col_dofs) {
59 const int nb_integration_pts = getGaussPts().size2();
60 mat.resize(nb_row_dofs, nb_col_dofs,
false);
63 auto t_w = getFTensor0IntegrationWeight();
64 const double vol = getMeasure();
65 for (
int gg = 0; gg != nb_integration_pts; ++gg) {
66 const double a = t_w * vol;
67 for (
int rr = 0; rr != nb_row_dofs; ++rr) {
69 for (
int cc = 0; cc != nb_col_dofs; ++cc) {
70 mat(rr, cc) +=
a * t_row_base * t_col_base;
80 if (row_side != col_side || row_type != col_type) {
81 transMat.resize(nb_col_dofs, nb_row_dofs,
false);
82 noalias(transMat) = trans(mat);
104 :
OpEle(
"u",
OpEle::OPROW), commonData(data) {}
109 vecF.resize(nb_dofs,
false);
112 const int nb_integration_pts = getGaussPts().size2();
115 auto t_w = getFTensor0IntegrationWeight();
117 const double vol = getMeasure();
118 for (
int gg = 0; gg != nb_integration_pts; ++gg) {
119 const double a = vol * t_w;
120 const double f =
a *
r * t_val * (1 - t_val /
k);
121 for (
int rr = 0; rr != nb_dofs; ++rr) {
122 const double b =
f * t_base;
131 CHKERR VecSetOption(getFEMethod()->ts_F, VEC_IGNORE_NEGATIVE_INDICES,
153 :
OpEle(
"u",
OpEle::OPROW), commonData(data) {}
158 vecF.resize(nb_dofs,
false);
161 const int nb_integration_pts = getGaussPts().size2();
163 auto t_grad = getFTensor1FromMat<DIM>(commonData->grad);
166 auto t_w = getFTensor0IntegrationWeight();
169 const double vol = getMeasure();
170 for (
int gg = 0; gg != nb_integration_pts; ++gg) {
171 const double a = vol * t_w;
172 for (
int rr = 0; rr != nb_dofs; ++rr) {
173 vecF[rr] +=
a * (t_base * t_dot_val +
D * t_diff_base(
i) * t_grad(
i));
182 CHKERR VecSetOption(getFEMethod()->ts_F, VEC_IGNORE_NEGATIVE_INDICES,
205 :
OpEle(
"u",
"u",
OpEle::OPROWCOL), commonData(data) {
209 EntityType col_type,
EntData &row_data,
212 const int nb_row_dofs = row_data.
getIndices().size();
213 const int nb_col_dofs = col_data.
getIndices().size();
214 if (nb_row_dofs && nb_col_dofs) {
215 mat.resize(nb_row_dofs, nb_col_dofs,
false);
218 const int nb_integration_pts = getGaussPts().size2();
221 auto t_w = getFTensor0IntegrationWeight();
224 const double ts_a = getFEMethod()->ts_a;
225 const double vol = getMeasure();
226 for (
int gg = 0; gg != nb_integration_pts; ++gg) {
227 const double a = vol * t_w;
228 for (
int rr = 0; rr != nb_row_dofs; ++rr) {
233 for (
int cc = 0; cc != nb_col_dofs; ++cc) {
234 mat(rr, cc) +=
a * (t_row_base * t_col_base * ts_a +
235 D * t_row_diff_base(
i) * t_col_diff_base(
i));
248 if (row_side != col_side || row_type != col_type) {
249 transMat.resize(nb_col_dofs, nb_row_dofs,
false);
250 noalias(transMat) = trans(mat);
252 &transMat(0, 0), ADD_VALUES);
272 : dM(dm), postProc(post_proc){};
281 CHKERR postProc->writeFile(
282 "out_level_" + boost::lexical_cast<std::string>(ts_step) +
".h5m");
296 int main(
int argc,
char *argv[]) {
299 const char param_file[] =
"param_file.petsc";
311 DMType dm_name =
"DMMOFEM";
332 boost::shared_ptr<CommonData> data(
new CommonData());
334 auto val_ptr = boost::shared_ptr<VectorDouble>(data, &data->val);
335 auto dot_val_ptr = boost::shared_ptr<VectorDouble>(data, &data->dot_val);
336 auto grad_ptr = boost::shared_ptr<MatrixDouble>(data, &data->grad);
340 boost::shared_ptr<Ele> vol_ele_slow_rhs(
new Ele(m_field));
341 boost::shared_ptr<Ele> vol_ele_stiff_rhs(
new Ele(m_field));
342 boost::shared_ptr<Ele> vol_ele_stiff_lhs(
new Ele(m_field));
345 vol_ele_slow_rhs->getOpPtrVector().push_back(
352 auto solve_for_g = [&]() {
354 if (*(vol_ele_slow_rhs->vecAssembleSwitch)) {
355 CHKERR VecGhostUpdateBegin(vol_ele_slow_rhs->ts_F, ADD_VALUES,
357 CHKERR VecGhostUpdateEnd(vol_ele_slow_rhs->ts_F, ADD_VALUES,
359 CHKERR VecAssemblyBegin(vol_ele_slow_rhs->ts_F);
360 CHKERR VecAssemblyEnd(vol_ele_slow_rhs->ts_F);
361 *vol_ele_slow_rhs->vecAssembleSwitch =
false;
363 CHKERR KSPSolve(data->ksp, vol_ele_slow_rhs->ts_F,
364 vol_ele_slow_rhs->ts_F);
368 vol_ele_slow_rhs->postProcessHook = solve_for_g;
370 auto det_ptr = boost::make_shared<VectorDouble>();
371 auto jac_ptr = boost::make_shared<MatrixDouble>();
372 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
374 vol_ele_stiff_rhs->getOpPtrVector().push_back(
376 vol_ele_stiff_rhs->getOpPtrVector().push_back(
378 vol_ele_stiff_rhs->getOpPtrVector().push_back(
380 vol_ele_stiff_rhs->getOpPtrVector().push_back(
382 vol_ele_stiff_rhs->getOpPtrVector().push_back(
384 vol_ele_stiff_rhs->getOpPtrVector().push_back(
388 vol_ele_stiff_lhs->getOpPtrVector().push_back(
390 vol_ele_stiff_lhs->getOpPtrVector().push_back(
392 vol_ele_stiff_lhs->getOpPtrVector().push_back(
394 vol_ele_stiff_lhs->getOpPtrVector().push_back(
398 auto vol_rule = [](
int,
int,
int p) ->
int {
return 2 * p; };
399 vol_ele_slow_rhs->getRuleHook = vol_rule;
400 vol_ele_stiff_rhs->getRuleHook = vol_rule;
401 vol_ele_stiff_lhs->getRuleHook = vol_rule;
405 auto post_proc = boost::make_shared<PostProcEle>(m_field);
406 boost::shared_ptr<ForcesAndSourcesCore>
null;
410 auto u_ptr = boost::make_shared<VectorDouble>();
411 post_proc->getOpPtrVector().push_back(
413 post_proc->getOpPtrVector().push_back(
417 post_proc->getPostProcMesh(), post_proc->getMapGaussPts(),
432 auto dm = simple_interface->getDM();
440 1,
BLOCKSET, 2, inner_surface,
true);
441 if (!inner_surface.empty()) {
442 Range inner_surface_verts;
443 CHKERR moab.get_connectivity(inner_surface, inner_surface_verts,
false);
445 u0, MBVERTEX, inner_surface_verts,
"u");
453 Skinner skin(&m_field.get_moab());
457 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
458 CHKERR pcomm->filter_pstatus(edges, PSTATUS_SHARED | PSTATUS_MULTISHARED,
459 PSTATUS_NOT, -1, &edges_part);
461 CHKERR moab.get_connectivity(edges_part, edges_verts,
false);
465 simple_interface->getProblemName(),
"u",
466 unite(edges_verts, edges_part));
470 CHKERR MatZeroEntries(data->M);
471 boost::shared_ptr<Ele> vol_mass_ele(
new Ele(m_field));
472 vol_mass_ele->getOpPtrVector().push_back(
new OpAssembleMass(data));
475 CHKERR MatAssemblyBegin(data->M, MAT_FINAL_ASSEMBLY);
476 CHKERR MatAssemblyEnd(data->M, MAT_FINAL_ASSEMBLY);
480 data->ksp =
createKSP(m_field.get_comm());
481 CHKERR KSPSetOperators(data->ksp, data->M, data->M);
482 CHKERR KSPSetFromOptions(data->ksp);
483 CHKERR KSPSetUp(data->ksp);
486 auto ts =
createTS(m_field.get_comm());
488 CHKERR TSSetType(ts, TSARKIMEX);
489 CHKERR TSARKIMEXSetType(ts, TSARKIMEXA2);
493 vol_ele_stiff_lhs,
null,
null);
496 vol_ele_stiff_rhs,
null,
null);
499 vol_ele_slow_rhs,
null,
null);
502 boost::shared_ptr<Monitor> monitor_ptr(
new Monitor(dm, post_proc));
504 monitor_ptr,
null,
null);
514 CHKERR TSSetDuration(ts, PETSC_DEFAULT, ftime);
515 CHKERR TSSetSolution(ts, X);
516 CHKERR TSSetFromOptions(ts);