v0.15.5
Loading...
Searching...
No Matches
Functions | Variables
geometry_surface_fit.cpp File Reference

Fit GEOMETRY mid-edge nodes to a fine surface using closest points. More...

#include <MoFEM.hpp>
#include <PostProc.hpp>
#include <cmath>
#include <cstdio>
#include <vector>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "Fit GEOMETRY mid-edge nodes to a fine surface.\n\n"
 

Detailed Description

Fit GEOMETRY mid-edge nodes to a fine surface using closest points.

Algorithm (summary):

Definition in file geometry_surface_fit.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 26 of file geometry_surface_fit.cpp.

26 {
27 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
28
29 try {
30 DMType dm_name = "DMMOFEM";
31 CHKERR DMRegister_MoFEM(dm_name);
32
33 moab::Core coarse_core;
34 moab::Interface &coarse_moab = coarse_core;
35 MoFEM::Core core(coarse_moab);
36 MoFEM::Interface &m_field = core;
37
38 moab::Core fine_core;
39 moab::Interface &fine_moab = fine_core;
40
41 // Options (inputs/outputs and optimization parameters).
42 char coarse_file[255] = "coarse.h5m";
43 char surface_file[255] = "surface.h5m";
44 char output_file[255] = "out_geometry_fit.h5m";
45 char output_postproc[255] = "geometry_fit_postproc.h5m";
46 double planar_angle_deg = 2.0;
47 double max_disp_factor = 0.3;
48 PetscBool write_postproc = PETSC_TRUE;
49 PetscBool debug_surfaces = PETSC_FALSE;
50
51 // Parse CLI options.
52 PetscOptionsBegin(m_field.get_comm(), "", "geometry fit tool", "none");
53 CHKERR PetscOptionsString("-coarse_file", "coarse 3d mesh file name", "",
54 coarse_file, coarse_file, 255, PETSC_NULLPTR);
55 CHKERR PetscOptionsString("-surface_file", "fine surface mesh file name",
56 "", surface_file, surface_file, 255,
57 PETSC_NULLPTR);
58 CHKERR PetscOptionsString("-output_file", "output mesh file name", "",
59 output_file, output_file, 255, PETSC_NULLPTR);
60 CHKERR PetscOptionsString("-output_postproc",
61 "output postprocess mesh file name", "",
62 output_postproc, output_postproc, 255,
63 PETSC_NULLPTR);
64 CHKERR PetscOptionsReal(
65 "-planar_angle_deg",
66 "angle threshold in degrees to skip planar edges", "",
67 planar_angle_deg, &planar_angle_deg, PETSC_NULLPTR);
68 CHKERR PetscOptionsReal(
69 "-max_midnode_disp_factor",
70 "skip adjustment if |delta| > factor * edge length", "",
71 max_disp_factor, &max_disp_factor, PETSC_NULLPTR);
72 CHKERR PetscOptionsBool("-write_postproc",
73 "write postprocess mesh output", "",
74 write_postproc, &write_postproc, PETSC_NULLPTR);
75 CHKERR PetscOptionsBool("-debug",
76 "dump intermediate fine-surface feature VTKs", "",
77 debug_surfaces, &debug_surfaces, PETSC_NULLPTR);
78 PetscOptionsEnd();
79
80 MOFEM_LOG_CHANNEL("WORLD");
81 MOFEM_LOG_TAG("WORLD", "geometry_surface_fit");
82
83 // Load coarse (volume) and fine (surface) meshes.
84
85 auto simple = m_field.getInterface<Simple>();
86 CHKERR simple->loadFile("", std::string(coarse_file));
87 CHKERR fine_moab.load_file(surface_file);
88
89 // Coarse volume mesh must exist to define skin edges.
90 Range coarse_vols;
91 CHKERR coarse_moab.get_entities_by_dimension(0, 3, coarse_vols);
92 if (coarse_vols.empty()) {
93 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
94 "no 3d entities found in coarse mesh");
95 }
96
97
98 // Build fine surface triangles (use skin if volume exists).
99 Range fine_vols;
100 Range fine_tris;
101 CHKERR fine_moab.get_entities_by_dimension(0, 3, fine_vols);
102 if (!fine_vols.empty()) {
103 Skinner fine_skinner(&fine_moab);
104 CHKERR fine_skinner.find_skin(0, fine_vols, false, fine_tris);
105 } else {
106 CHKERR fine_moab.get_entities_by_dimension(0, 2, fine_tris);
107 }
108 if (fine_tris.empty()) {
109 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
110 "no surface triangles found in fine mesh");
111 }
112
113 bool has_geometry = false;
114 auto base = AINSWORTH_LEGENDRE_BASE;
115 if (m_field.check_field("GEOMETRY")) {
116 has_geometry = true;
117 base = m_field.get_field_structure("GEOMETRY")->getApproxBase();
118 }
119 simple->addDomainField("GEOMETRY", H1, base, 3);
120 CHKERR simple->setFieldOrder("GEOMETRY", 2);
121 CHKERR simple->setUp(PETSC_FALSE);
122
123 if (!has_geometry) {
124 Projection10NodeCoordsOnField ent_method(m_field, "GEOMETRY");
125 CHKERR m_field.loop_dofs("GEOMETRY", ent_method);
126 }
127
128 // Project mid-edge DOFs to fine surface using closest-point tagging.
130 m_field, fine_moab, fine_tris, "GEOMETRY", planar_angle_deg,
131 max_disp_factor, debug_surfaces);
132 CHKERR m_field.loop_entities("GEOMETRY", fit_method);
133
134 // Write updated mesh + optional outputs.
135 CHKERR coarse_moab.write_file(output_file);
136 MOFEM_LOG("WORLD", Sev::inform) << "Wrote file " << output_file;
137 if (write_postproc) {
138 auto pip = m_field.getInterface<PipelineManager>();
139
140 auto post_proc_mesh = boost::make_shared<moab::Core>();
141 auto post_proc_begin =
142 boost::make_shared<PostProcBrokenMeshInMoabBaseBegin>(m_field,
143 post_proc_mesh);
144 auto post_proc_end = boost::make_shared<PostProcBrokenMeshInMoabBaseEnd>(
145 m_field, post_proc_mesh);
146
149 auto post_proc_fe =
150 boost::make_shared<PostProcEleDomain>(m_field, post_proc_mesh);
151 CHKERR AddHOOps<3, 3, 3>::add(post_proc_fe->getOpPtrVector(), {H1},
152 "GEOMETRY");
153 auto x_ptr = boost::make_shared<MatrixDouble>();
154 post_proc_fe->getOpPtrVector().push_back(
155 new OpCalculateVectorFieldValues<3>("GEOMETRY", x_ptr));
157 post_proc_fe->getOpPtrVector().push_back(new OpPPMap(
158 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(), {},
159 {{"GEOMETRY", x_ptr}}, {}, {}));
160
161 pip->getDomainRhsFE() = post_proc_fe;
162
164 post_proc_begin->getFEMethod());
165 CHKERR pip->loopFiniteElements();
167 post_proc_end->getFEMethod());
168 CHKERR post_proc_end->writeFile(output_postproc);
169 MOFEM_LOG("WORLD", Sev::inform)
170 << "Wrote postprocess mesh " << output_postproc;
171 }
172 }
174
176 return 0;
177}
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
@ H1
continuous field
Definition definitions.h:85
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define CHKERR
Inline error check.
PostProcEleByDim< SPACE_DIM >::PostProcEleDomain PostProcEleDomain
static char help[]
PetscErrorCode DMoFEMPostProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
Definition DMMoFEM.cpp:546
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
PetscErrorCode DMoFEMPreProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
Definition DMMoFEM.cpp:536
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
virtual MoFEMErrorCode loop_entities(const std::string field_name, EntityMethod &method, Range const *const ents=nullptr, int verb=DEFAULT_VERBOSITY)=0
Loop over field entities.
virtual bool check_field(const std::string &name) const =0
check if field is in database
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
Add operators pushing bases from local to physical configuration.
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:82
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:118
Deprecated interface functions.
FieldApproximationBase getApproxBase() const
Get approximation basis type.
Specialization for double precision vector field values calculation.
Post post-proc data at points from hash maps.
PipelineManager interface.
MoFEM::VolumeElementForcesAndSourcesCore VolEle
Project edge mid-nodes onto a fine surface mesh using closest points.
Projection of edge entities with one mid-node on hierarchical basis.
Simple interface for fast problem set-up.
Definition Simple.hpp:27
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition Simple.cpp:191
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

Variable Documentation

◆ help

char help[] = "Fit GEOMETRY mid-edge nodes to a fine surface.\n\n"
static

Definition at line 24 of file geometry_surface_fit.cpp.