719 {
723
724 auto dm =
simple->getDM();
725 auto ts = pipeline_mng->createTSIM();
726
727 auto add_extra_finite_elements_to_solver_pipelines = [&]() {
729
730 auto pre_proc_ptr = boost::make_shared<FEMethod>();
731 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
732 auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
733
734 auto time_scale = boost::make_shared<ExampleTimeScale>();
735
736 auto get_bc_hook_rhs = [this, pre_proc_ptr, time_scale]() {
738 CHKERR EssentialPreProc<DisplacementCubitBcData>(
mField, pre_proc_ptr,
739 {time_scale}, false)();
741 };
742
743 pre_proc_ptr->preProcessHook = get_bc_hook_rhs;
744
745 auto get_post_proc_hook_rhs = [this, post_proc_rhs_ptr]() {
747 CHKERR EssentialPreProcReaction<DisplacementCubitBcData>(
748 mField, post_proc_rhs_ptr,
nullptr, Sev::verbose)();
749 CHKERR EssentialPostProcRhs<DisplacementCubitBcData>(
750 mField, post_proc_rhs_ptr, 1.)();
752 };
753 auto get_post_proc_hook_lhs = [this, post_proc_lhs_ptr]() {
755 CHKERR EssentialPostProcLhs<DisplacementCubitBcData>(
756 mField, post_proc_lhs_ptr, 1.)();
758 };
759 post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
760 post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs;
761
762
764 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
765 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
766 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
767 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
769 };
770
771
772
773 CHKERR add_extra_finite_elements_to_solver_pipelines();
774
775 auto create_vertex_post_proc = [&]() {
776 using VertexStateTags = std::vector<std::tuple<std::string, Tag, int>>;
777 auto moab_vert_post_proc_ptr = boost::make_shared<moab::Core>();
778 auto fe_post_proc_ptr = boost::make_shared<DomainEle>(
mField);
779
780 auto source_fe_ptr =
782 pipeline_mng->getDomainRhsFE());
783 if (!source_fe_ptr) {
785 "Missing domain integration rule for vertex output");
786 }
787 fe_post_proc_ptr->getRuleHook = source_fe_ptr->getRuleHook;
788
790 OpMoabVertPostProc(boost::shared_ptr<moab::Core> moab_ptr,
791 moab::Interface &source_mesh, int partition,
792 VertexStateTags state_tags)
794 sourceMesh(source_mesh), partitionId(partition),
795 stateTags(
std::
move(state_tags)) {}
796
799
800 const int nb_gauss_pts = getGaussPts().size2();
801 if (!nb_gauss_pts)
803
804 const auto &coords = getCoordsAtGaussPts();
805#ifndef NDEBUG
806 if (coords.size1() != nb_gauss_pts || coords.size2() != 3) {
808 "Invalid integration-point coordinates for vertex output");
809 }
810#endif
812 CHKERR moabPtr->create_vertices(coords.data().data(), nb_gauss_pts,
814
815 Tag partition_tag = 0;
816 const int default_partition = -1;
817 CHKERR moabPtr->tag_get_handle(
818 "PARALLEL_PARTITION", 1, MB_TYPE_INTEGER, partition_tag,
819 MB_TAG_CREAT | MB_TAG_SPARSE, &default_partition);
820 CHKERR moabPtr->tag_clear_data(partition_tag,
vertices, &partitionId);
821
822 const auto entity = getFEEntityHandle();
823 for (
const auto &[
name,
tag, num_components] : stateTags) {
825 const std::vector<double> default_values(num_components, 0.0);
826 CHKERR moabPtr->tag_get_handle(
827 name.c_str(), num_components, MB_TYPE_DOUBLE, output_tag,
828 MB_TAG_CREAT | MB_TAG_SPARSE, default_values.data());
829
830 const void *state_data = nullptr;
831 int state_size = 0;
832 const auto rval = sourceMesh.tag_get_by_ptr(
833 tag, &entity, 1, &state_data, &state_size);
834 if (rval == MB_TAG_NOT_FOUND)
835 continue;
837 if (!state_data || !state_size)
838 continue;
839 if (state_size < 0 || state_size % num_components != 0) {
841 "Inconsistent state tag size for %s",
name.c_str());
842 }
843
844 const int required_size = nb_gauss_pts * num_components;
845 if (state_size < required_size) {
846
847 std::vector<double>
values(required_size, 0.0);
848 std::copy_n(static_cast<const double *>(state_data), state_size,
851 } else {
852
854 }
855 }
856
858 }
859
860 private:
861 boost::shared_ptr<moab::Core> moabPtr;
862 moab::Interface &sourceMesh;
863 int partitionId;
864 VertexStateTags stateTags;
865 };
866
867 VertexStateTags state_tags;
869 state_tags.emplace_back(
name,
tag, num_components);
870 auto &pip = fe_post_proc_ptr->getOpPtrVector();
872 (AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(pip, {
H1},
"GEOMETRY")),
873 "Cannot set geometry for integration-point output");
874 pip.push_back(new OpMoabVertPostProc(moab_vert_post_proc_ptr,
876 std::move(state_tags)));
877
878 return std::make_pair(moab_vert_post_proc_ptr, fe_post_proc_ptr);
879 };
880
881 auto create_monitor_fe = [this, dm](auto &&post_proc_fe,
882 auto &&post_proc_vert) {
883 return boost::make_shared<Monitor>(dm.get(), post_proc_fe, post_proc_vert,
885 };
886
887
888 boost::shared_ptr<FEMethod> null_fe;
895 auto monitor_ptr = create_monitor_fe(
898 null_fe, monitor_ptr);
899
901
902
903 double ftime = 1;
904 CHKERR TSSetMaxTime(ts, ftime);
905 CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
906
908 CHKERR TSSetI2Jacobian(ts,
B,
B, PETSC_NULLPTR, PETSC_NULLPTR);
911 CHKERR TSSetFromOptions(ts);
912
918
919 CHKERR TSGetTime(ts, &ftime);
920
921 PetscInt steps, snesfails, rejects, nonlinits, linits;
922 CHKERR TSGetStepNumber(ts, &steps);
923 CHKERR TSGetSNESFailures(ts, &snesfails);
924 CHKERR TSGetStepRejections(ts, &rejects);
925 CHKERR TSGetSNESIterations(ts, &nonlinits);
926 CHKERR TSGetKSPIterations(ts, &linits);
928 "steps %d (%d rejected, %d SNES fails), ftime %g, nonlinits "
929 "%d, linits %d",
930 steps, rejects, snesfails, ftime, nonlinits, linits);
931
933}
std::vector< int > vertices
PetscErrorCode TSAdaptCreateAmentum(TSAdapt adapt)
SmartPetscObj< Vec > values
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
auto createDMMatrix(DM dm)
Get smart matrix from DM.
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
Set Monitor To TS solver.
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Data on single entity (This is passed as argument to DataOperator::doWork)
static MoFEMErrorCode preStepFun(TS ts)
static MoFEMErrorCode postStepDestroy()
static MoFEMErrorCode postStepInitialise(UmatExample *example_ptr)
static MoFEMErrorCode postStepFun(TS ts)