12 int order_col,
int order_data);
16 using ForcesAndSourcesCore::dataOnElement;
19 using ForcesAndSourcesCore::ForcesAndSourcesCore;
33 Vec vecsToMapFrom[] = PETSC_NULLPTR,
34 Vec vecsToMapTo[] = PETSC_NULLPTR);
35 MoFEMErrorCode
reSetUp(std::vector<std::string> fIelds,
36 std::vector<int> oRders, BitRefLevel bIt);
45 boost::shared_ptr<DomainEle>
feRhs;
46 boost::shared_ptr<DomainEle>
feLhs;
53 Vec vecIn = PETSC_NULLPTR);
56 Vec vecsToMapFrom[], Vec vecsToMapTo[]);
67 Range els_to_flip, PetscInt num_vecs,
68 Vec vecs_to_map_from[],
69 Vec vecs_to_map_to[]) {
81 SmartPetscObj<DM> &intermediate_dm,
85 MOFEM_LOG(
"REMESHING", Sev::inform) <<
"Set up sub DM for mapping";
91 auto create_sub_dm = [&]() {
94 auto create_impl = [&]() {
96 CHKERR DMSetType(sub_dm,
"DMMOFEM");
97 CHKERR DMMoFEMCreateSubDM(sub_dm, intermediate_dm,
"SUB_MAPPING");
98 CHKERR DMMoFEMAddElement(sub_dm,
simple->getDomainFEName());
99 CHKERR DMMoFEMSetSquareProblem(sub_dm, PETSC_TRUE);
100 CHKERR DMMoFEMSetDestroyProblem(sub_dm, PETSC_TRUE);
102 MOFEM_LOG(
"REMESHING", Sev::inform) <<
"Created sub DM";
104 for (
auto f : {
"T",
"TAU",
"EP"}) {
105 CHKERR DMMoFEMAddSubFieldRow(sub_dm, f,
106 boost::make_shared<Range>(els_to_add));
107 CHKERR DMMoFEMAddSubFieldCol(sub_dm, f,
108 boost::make_shared<Range>(els_to_add));
111 auto bit = BitRefLevel().set();
116 CHKERR DMSubDMSetUp_MoFEM(sub_dm);
127 MOFEM_LOG(
"REMESHING", Sev::inform) <<
"Set up sub DM for mapping <= done";
132 std::vector<int> orders,
138 auto add_ents_order_to_field =
140 const std::initializer_list<std::string> &f,
141 const std::initializer_list<EntityType> &
t,
int _order) {
152 for (
size_t i = 0;
i < fields.size(); ++
i) {
153 CHKERR add_ents_order_to_field(
m_field, {fields[
i]}, {MBTRI}, orders[
i]);
158 simple->getDomainFEName());
169 const Problem *prb_ptr;
174 <<
"Number of initial row dofs: " << nb_init_row_dofs;
182 auto remove_dofs_on_ents = [&](std::string field,
const Range &ents) {
184 return prb_mng->removeDofsOnEntities(
"SUB_MAPPING", field, ents);
186 return prb_mng->removeDofsOnEntitiesNotDistributed(
"SUB_MAPPING", field,
190 for (std::string field : {
"EP",
"TAU",
"T"}) {
191 remove_dofs_on_ents(field, els_to_remove);
193 nb_init_row_dofs = prb_ptr->getNbDofsRow();
196 <<
"Number of row dofs after removing " << field
197 <<
" field: " << nb_init_row_dofs;
204 Range els_to_add, Vec vec_in) {
207 SmartPetscObj<Vec> smart_vec_in;
209 smart_vec_in = SmartPetscObj<Vec>(vec_in,
true);
211 MOFEM_LOG(
"REMESHING", Sev::inform) <<
"Got past smart vector";
213 feRhs->getOpPtrVector().clear();
215 MOFEM_LOG(
"REMESHING", Sev::inform) <<
"Cleared RHS FE";
219 auto vol_rule = [](int, int,
int ao) {
return 2 * ao +
geom_order; };
223 feRhs->getRuleHook = [](int, int, int) {
return -1; };
226 feLhs->getRuleHook = [](int, int, int) {
return -1; };
230 auto T_ptr = boost::make_shared<VectorDouble>();
231 auto TAU_ptr = boost::make_shared<VectorDouble>();
232 auto EP_ptr = boost::make_shared<MatrixDouble>();
234 auto set_domain_rhs = [&](
auto &pip) {
239 auto old_T_ptr = boost::make_shared<VectorDouble>();
240 auto old_TAU_ptr = boost::make_shared<VectorDouble>();
241 auto old_EP_ptr = boost::make_shared<MatrixDouble>();
243 auto old_el_ops = [&](
auto &pip) {
249 new OpCalculateScalarFieldValues(
"T", old_T_ptr, smart_vec_in));
251 new OpCalculateScalarFieldValues(
"TAU", old_TAU_ptr, smart_vec_in));
252 pip.push_back(
new OpCalculateTensor2SymmetricFieldValues<SPACE_DIM>(
253 "EP", old_EP_ptr, smart_vec_in));
255 pip.push_back(
new OpCalculateScalarFieldValues(
"T", old_T_ptr));
256 pip.push_back(
new OpCalculateScalarFieldValues(
"TAU", old_TAU_ptr));
257 pip.push_back(
new OpCalculateTensor2SymmetricFieldValues<SPACE_DIM>(
270 auto new_el_ops = [&](
auto &pp_fe,
auto &&p) {
273 auto new_T_ptr = boost::make_shared<VectorDouble>();
274 auto new_TAU_ptr = boost::make_shared<VectorDouble>();
275 auto new_EP_ptr = boost::make_shared<MatrixDouble>();
278 new OpCalculateScalarFieldValues(
"T", new_T_ptr, smart_vec_in));
280 new OpCalculateScalarFieldValues(
"TAU", new_TAU_ptr, smart_vec_in));
281 pip.push_back(
new OpCalculateTensor2SymmetricFieldValues<SPACE_DIM>(
282 "EP", new_EP_ptr, smart_vec_in));
284 MOFEM_LOG(
"REMESHING", Sev::inform) <<
"In other branch of child ops";
285 pip.push_back(
new OpCalculateScalarFieldValues(
"T", new_T_ptr));
286 pip.push_back(
new OpCalculateScalarFieldValues(
"TAU", new_TAU_ptr));
287 pip.push_back(
new OpCalculateTensor2SymmetricFieldValues<SPACE_DIM>(
293 "T", old_T_ptr,
nullptr, new_T_ptr,
nullptr,
m_field));
296 "TAU", old_TAU_ptr,
nullptr, new_TAU_ptr,
nullptr,
m_field));
300 "EP", old_EP_ptr,
nullptr, new_EP_ptr,
nullptr,
m_field));
306 auto op_range =
new OpLoopRange<DomainEleOnRange>(
308 boost::make_shared<Range>(els_to_flip), Sev::noisy);
310 op_range->getRangeFEPtr()->getRuleHook = [](int, int, int) {
return -1; };
313 pip.push_back(op_range);
316 CHK_MOAB_THROW(new_el_ops(pip, old_el_ops(op_range->getOpPtrVector())),
317 "failed to loop over child ops");
322 auto set_domain_lhs = [&](
auto &pip) {
327 using OpLhsScalarLeastSquaresProj = FormsIntegrators<DomainEleOp>::Assembly<
329 pip.push_back(
new OpLhsScalarLeastSquaresProj(
"T",
"T"));
330 pip.push_back(
new OpLhsScalarLeastSquaresProj(
"TAU",
"TAU"));
345 SmartPetscObj<DM> &intermediate_dm,
347 Vec vecs_to_map_from[],
348 Vec vecs_to_map_to[]) {
354 auto post_proc = [&](
auto dm, std::string file_name) {
357 auto T_ptr = boost::make_shared<VectorDouble>();
358 auto TAU_ptr = boost::make_shared<VectorDouble>();
359 auto EP_ptr = boost::make_shared<MatrixDouble>();
361 auto post_proc_fe = boost::make_shared<PostProcEle>(
m_field);
363 using OpPPMap = OpPostProcMapInMoab<SPACE_DIM, SPACE_DIM>;
365 post_proc_fe->getOpPtrVector().push_back(
366 new OpCalculateScalarFieldValues(
"T", T_ptr));
367 post_proc_fe->getOpPtrVector().push_back(
368 new OpCalculateScalarFieldValues(
"TAU", TAU_ptr));
369 post_proc_fe->getOpPtrVector().push_back(
370 new OpCalculateTensor2SymmetricFieldValues<SPACE_DIM>(
"EP", EP_ptr));
373 post_proc_fe->getOpPtrVector().push_back(
375 new OpPPMap(post_proc_fe->getPostProcMesh(),
376 post_proc_fe->getMapGaussPts(),
378 {{
"T", T_ptr}, {
"TAU", TAU_ptr}},
390 CHKERR DMoFEMLoopFiniteElements(dm,
simple->getDomainFEName(),
392 CHKERR post_proc_fe->writeFile(file_name);
397 auto null_fe = boost::shared_ptr<FEMethod>();
399 CHKERR DMMoFEMKSPSetComputeOperators(sub_dm,
simple->getDomainFEName(), feLhs,
405 CHKERR KSPSetDM(ksp, sub_dm);
406 CHKERR KSPSetFromOptions(ksp);
412 auto tmp_D = createDMVector(intermediate_dm);
413 CHKERR DMoFEMMeshToLocalVector(intermediate_dm, tmp_D, INSERT_VALUES,
415 CHKERR VecGhostUpdateBegin(tmp_D, INSERT_VALUES, SCATTER_FORWARD);
416 CHKERR VecGhostUpdateEnd(tmp_D, INSERT_VALUES, SCATTER_FORWARD);
418 auto D = createDMVector(sub_dm);
419 auto F = vectorDuplicate(
D);
421 for (
int i = 0;
i < num_vecs; ++
i) {
422 CHKERR VecGhostUpdateBegin(vecs_to_map_from[
i], INSERT_VALUES,
424 CHKERR VecGhostUpdateEnd(vecs_to_map_from[
i], INSERT_VALUES,
426 CHKERR DMoFEMMeshToLocalVector(intermediate_dm, vecs_to_map_from[
i],
427 INSERT_VALUES, SCATTER_REVERSE);
430 CHKERR VecGhostUpdateBegin(
F, INSERT_VALUES, SCATTER_FORWARD);
431 CHKERR VecGhostUpdateEnd(
F, INSERT_VALUES, SCATTER_FORWARD);
433 CHKERR DMoFEMLoopFiniteElements(sub_dm,
simple->getDomainFEName(), feRhs);
434 CHKERR VecGhostUpdateBegin(
F, ADD_VALUES, SCATTER_REVERSE);
435 CHKERR VecGhostUpdateEnd(
F, ADD_VALUES, SCATTER_REVERSE);
441 CHKERR DMoFEMMeshToLocalVector(sub_dm,
D, INSERT_VALUES, SCATTER_REVERSE);
442 CHKERR DMoFEMMeshToLocalVector(intermediate_dm, vecs_to_map_to[
i],
443 INSERT_VALUES, SCATTER_FORWARD);
444 CHKERR VecGhostUpdateBegin(vecs_to_map_to[
i], INSERT_VALUES,
446 CHKERR VecGhostUpdateEnd(vecs_to_map_to[
i], INSERT_VALUES, SCATTER_FORWARD);
448 CHKERR post_proc(intermediate_dm,
"out_map_" + std::to_string(
i) +
".h5m");
454 MOFEM_LOG(
"REMESHING", Sev::inform) <<
"Mapped thermoplastic state variables";
void simple(double P1[], double P2[], double P3[], double c[], const int N)
constexpr int SPACE_DIM
[Define dimension]
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ 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 DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
#define MOFEM_LOG(channel, severity)
Log.
virtual MoFEMErrorCode modify_problem_mask_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set dof mask ref level for problem
virtual MoFEMErrorCode modify_problem_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set ref level for problem
FTensor::Index< 'i', SPACE_DIM > i
auto createKSP(MPI_Comm comm)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
constexpr double t
plate stiffness
Rhs for mapping scalar fields with least squares.
Rhs for mapping symmetric tensor fields with least squares.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MPI_Comm & get_comm() const =0
Deprecated interface functions.
Post post-proc data at points from hash maps.
DofIdx getNbDofsRow() const
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
boost::shared_ptr< Range > newEls
MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row, int order_col, int order_data)
static std::map< long int, MatrixDouble > mapRefCoords
MoFEMErrorCode postProcess()
SmartPetscObj< DM > intermediateDM
MoFEMErrorCode removeDofs(Range elsToRemove, Range elsToAdd)
MoFEMErrorCode solveMap(SmartPetscObj< DM > &subDM, SmartPetscObj< DM > &intermediateDM, PetscInt numVecs, Vec vecsToMapFrom[], Vec vecsToMapTo[])
SolutionMapping(MoFEM::Interface &m_field)
boost::shared_ptr< DomainEle > feRhs
MoFEMErrorCode reSetUp(std::vector< std::string > fIelds, std::vector< int > oRders, BitRefLevel bIt)
MoFEMErrorCode setUp(SmartPetscObj< DM > &subDM, SmartPetscObj< DM > &intermediateDM, Range elsToAdd, Range elsToFlip)
MoFEM::Interface & m_field
boost::shared_ptr< DomainEle > feLhs
MoFEMErrorCode mapFields(SmartPetscObj< DM > &intermediateDM, Range elsToRemove=Range(), Range elsToAdd=Range(), Range elsToFlip=Range(), PetscInt numVecs=1, Vec vecsToMapFrom[]=PETSC_NULLPTR, Vec vecsToMapTo[]=PETSC_NULLPTR)
MoFEMErrorCode pushOperators(Range elsToFlip, Range elsToAdd, Vec vecIn=PETSC_NULLPTR)
SmartPetscObj< DM > subDM
constexpr AssemblyType AT
constexpr IntegrationType IT
PetscBool is_distributed_mesh
int geom_order
Order if fixed.