17static char help[] =
"...\n\n";
36 86, -142, -193, -126, 0, 126, 193, 142, -86};
71 GAUSS>::OpMixDivTimesScalar<2>;
108 static std::vector<double>
rZ;
109 static std::vector<MatrixInt>
iI;
118 static double rhsSource(
const double x,
const double y,
const double);
119 static double lhsFlux(
const double x,
const double y,
const double);
138 const auto p = std::make_pair<int, int>(std::round(x), std::round(y));
141 if (p.first < 0 && p.first >=
m.size1())
143 if (p.second < 0 && p.second >=
m.size2())
156 const auto &intensity =
iI[
i];
168 return 1. /
m(idx.first, idx.second);
172 BoundaryOp(boost::shared_ptr<MatrixDouble> flux_ptr,
double &glob_flux)
178 auto t_flux = getFTensor1FromMat<3>(*
fluxPtr);
182 for (
auto gg = 0; gg != nb_gauss_pts; ++gg) {
201 char images_array_files[255] =
"out_arrays.txt";
203 images_array_files, 255, PETSC_NULLPTR);
207 auto read_images = [&]() {
209 in.open(images_array_files);
210 std::vector<int> values;
211 values.insert(values.end(), std::istream_iterator<int>(in),
212 std::istream_iterator<int>());
213 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Read data size " << values.size();
218 auto structure_data = [&](
auto &&data) {
219 constexpr double scale = 1e4;
220 auto it = data.begin();
221 if (it == data.end()) {
226 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Number of images " << *it;
228 for (; it != data.end();) {
229 rZ.emplace_back(*(it++) /
scale);
230 const auto r = *(it++);
231 const auto c = *(it++);
232 iI.emplace_back(r,
c);
234 <<
"Read data set " <<
rZ.back() <<
" size " <<
r <<
" by " <<
c;
236 for (
auto rit =
m.begin1(); rit !=
m.end1(); ++rit) {
237 for (
auto cit = rit.begin(); cit != rit.end(); ++cit) {
244 structure_data(read_images());
252 int window_shift = 0;
256 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Wave number " <<
k;
261 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Window shift " << window_shift;
263 if ((
rZ.size() - 1) % 2)
265 "Expected even number of images");
273 "Wrong Savitzky Golay order");
276 if (!d1_sg_data_window)
278 "Wrong Savitzky Golay window");
296 auto get_bounding_box = [&]() {
299 MOAB_THROW(moab.get_entities_by_type(0, MBVERTEX, verts));
301 ParallelComm *pcomm =
305 CHKERR pcomm->filter_pstatus(verts, PSTATUS_SHARED | PSTATUS_MULTISHARED,
306 PSTATUS_NOT, -1, &verts_part);
309 CHKERR moab.get_coords(verts_part, &*coords.data().begin());
311 std::array<double, 2> ave_coords{0, 0};
312 for (
auto v = 0;
v != verts_part.size(); ++
v) {
313 ave_coords[0] += coords(
v, 0);
314 ave_coords[1] += coords(
v, 1);
319 int local_count = verts_part.size();
321 MPI_Allreduce(&local_count, &global_count, 1, MPI_INT, MPI_SUM, comm);
322 std::array<double, 2> ave_coords_glob{0, 0};
323 MPI_Allreduce(ave_coords.data(), ave_coords.data(), 2, MPI_DOUBLE, MPI_SUM,
325 ave_coords_glob[0] /= global_count;
326 ave_coords_glob[1] /= global_count;
328 std::array<double, 2> max_coords{ave_coords_glob[0], ave_coords_glob[1]};
329 for (
auto v = 0;
v != verts_part.size(); ++
v) {
330 max_coords[0] = std::max(max_coords[0], coords(
v, 0));
331 max_coords[1] = std::max(max_coords[1], coords(
v, 1));
333 std::array<double, 2> max_coords_glob{0, 0};
334 MPI_Allreduce(max_coords.data(), max_coords_glob.data(), 2, MPI_DOUBLE,
337 std::array<double, 2> min_coords{max_coords_glob[0], max_coords_glob[1]};
338 for (
auto v = 0;
v != verts_part.size(); ++
v) {
339 min_coords[0] = std::min(min_coords[0], coords(
v, 0));
340 min_coords[1] = std::min(min_coords[1], coords(
v, 1));
342 std::array<double, 2> min_coords_glob{0, 0};
343 MPI_Allreduce(min_coords.data(), min_coords_glob.data(), 2, MPI_DOUBLE,
346 return std::array<double, LAST_BB>{ave_coords_glob[0], ave_coords_glob[1],
347 max_coords_glob[0], max_coords_glob[1],
348 min_coords_glob[0], min_coords_glob[1]};
388 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Base order " << base_order;
407 pipeline_mng->getDomainRhsFE().reset();
408 pipeline_mng->getBoundaryRhsFE().reset();
410 auto rule_vol = [](int, int,
int order) {
return 2 * (
order + 1); };
411 pipeline_mng->setBoundaryRhsIntegrationRule(rule_vol);
415 auto flux_ptr = boost::make_shared<MatrixDouble>();
416 pipeline_mng->getOpBoundaryRhsPipeline().push_back(
418 pipeline_mng->getOpBoundaryRhsPipeline().push_back(
422 CHKERR pipeline_mng->loopFiniteElements();
423 double global_flux_assembeld = 0;
424 MPI_Allreduce(&calc_flux, &global_flux_assembeld, 1, MPI_DOUBLE, MPI_SUM,
426 calc_flux = global_flux_assembeld;
439 pipeline_mng->getDomainRhsFE().reset();
440 pipeline_mng->getBoundaryRhsFE().reset();
442 auto rule_vol = [](int, int,
int order) {
return 2 * (
order + 1); };
443 pipeline_mng->setDomainLhsIntegrationRule(rule_vol);
444 pipeline_mng->setDomainRhsIntegrationRule(rule_vol);
449 pipeline_mng->getOpDomainLhsPipeline().push_back(
451 auto unity = []() {
return 1; };
452 pipeline_mng->getOpDomainLhsPipeline().push_back(
453 new OpHdivU(
"S",
"PHI", unity,
true));
454 pipeline_mng->getOpDomainRhsPipeline().push_back(
469 CHKERR KSPSetFromOptions(solver);
474 CHKERR KSPSolve(solver,
F, iD);
475 CHKERR VecGhostUpdateBegin(iD, INSERT_VALUES, SCATTER_FORWARD);
476 CHKERR VecGhostUpdateEnd(iD, INSERT_VALUES, SCATTER_FORWARD);
479 double i_lambda_flux;
483 <<
"iD flux " << std::scientific << i_lambda_flux;
499 auto post_proc_fe = boost::make_shared<PostProcEle>(
mField);
502 auto phi_ptr = boost::make_shared<VectorDouble>();
503 auto s_ptr = boost::make_shared<MatrixDouble>();
504 post_proc_fe->getOpPtrVector().push_back(
506 post_proc_fe->getOpPtrVector().push_back(
511 post_proc_fe->getOpPtrVector().push_back(
513 new OpPPMap(post_proc_fe->getPostProcMesh(),
514 post_proc_fe->getMapGaussPts(),
530 CHKERR post_proc_fe->writeFile(
"out_" + boost::lexical_cast<std::string>(
i) +
536int main(
int argc,
char *argv[]) {
539 const char param_file[] =
"param_file.petsc";
545 DMType dm_name =
"DMMOFEM";
550 moab::Core mb_instance;
551 moab::Interface &moab = mb_instance;
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, FIELD_DIM > OpDomainSource
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
#define CATCH_ERRORS
Catch errors.
#define MOAB_THROW(err)
Check error code of MoAB function and throw MoFEM exception.
@ L2
field with C-1 continuity
@ HCURL
field with continuous tangents
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
auto createDMVector(DM dm)
Get smart vector from DM.
MoFEMErrorCode loopFiniteElements(SmartPetscObj< DM > dm=nullptr)
Iterate finite elements.
SmartPetscObj< KSP > createKSP(SmartPetscObj< DM > dm=nullptr)
Create KSP (linear) solver.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'k', 3 > k
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMixDivTimesScalar< 2 > OpHdivU
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
MoFEM::OpBrokenTopoBase GAUSS
Gaussian quadrature integration.
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
const int * d1_normalisation[]
constexpr std::array< int, 3 > d1_savitzky_golay_w3_p2
constexpr std::array< int, 10 > d1_normalisation_p2
constexpr std::array< int, 9 > d1_savitzky_golay_w9_p4
constexpr std::array< int, 7 > d1_savitzky_golay_w7_p4
constexpr std::array< int, 5 > d1_savitzky_golay_w5_p2
constexpr std::array< int, 10 > d1_normalisation_p4
static int window_savitzky_golay
static int order_savitzky_golay
const int ** d1_savitzky_golay[]
constexpr std::array< int, 7 > d1_savitzky_golay_w7_p2
constexpr std::array< int, 5 > d1_savitzky_golay_w5_p4
const int * d1_savitzky_golay_p2[]
const int * d1_savitzky_golay_p4[]
constexpr std::array< int, 9 > d1_savitzky_golay_w9_p2
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, SPACE_DIM > OpMass
[Only used with Hooke equation (linear material model)]
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 3, 3 > OpHdivHdiv
Integrate Lhs base of flux (1/k) base of flux (FLUX x FLUX)
FTensor::Index< 'm', 3 > m
boost::shared_ptr< MatrixDouble > fluxPtr
MoFEMErrorCode doWork(int side, EntityType type, EntData &data)
Operator for linear form, usually to calculate values on right hand side.
BoundaryOp(boost::shared_ptr< MatrixDouble > flux_ptr, double &glob_flux)
MoFEMErrorCode readMesh()
static std::array< double, LAST_BB > aveMaxMin
static std::vector< MatrixInt > iI
static double rhsSource(const double x, const double y, const double)
MoFEMErrorCode solveSystem()
static std::pair< int, int > getCoordsInImage(double x, double y)
Example(MoFEM::Interface &m_field)
MoFEMErrorCode calculateFlux(double &calc_flux)
[Set up problem]
MoFEMErrorCode runProblem()
MoFEMErrorCode assembleSystemFlux()
MoFEM::Interface & mField
Reference to MoFEM interface.
MoFEMErrorCode assembleSystemIntensity()
[Calculate flux on boundary]
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
static double lhsFlux(const double x, const double y, const double)
MoFEMErrorCode setupProblem()
MoFEMErrorCode outputResults()
[Solve]
static int savitzkyGolayNormalisation
static std::vector< double > rZ
static const int * savitzkyGolayWeights
Add operators pushing bases from local to physical configuration.
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() 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.
default operator for EDGE element
auto getFTensor1Normal()
get edge normal NOTE: it should be used only in 2D analysis
Data on single entity (This is passed as argument to DataOperator::doWork)
auto getFTensor0IntegrationWeight()
Get integration weights.
@ OPSPACE
operator do Work is execute on space data
MatrixDouble & getGaussPts()
matrix of integration (Gauss) points for Volume Element
Get vector field for H-div approximation.
Specialization for double precision scalar field values calculation.
Post post-proc data at points from hash maps.
std::map< std::string, boost::shared_ptr< MatrixDouble > > DataMapMat
std::map< std::string, boost::shared_ptr< VectorDouble > > DataMapVec
PipelineManager interface.
boost::shared_ptr< FEMethod > & getDomainRhsFE()
Get domain right-hand side finite element.
boost::shared_ptr< FEMethod > & getDomainLhsFE()
Get domain left-hand side finite element.
boost::shared_ptr< FEMethod > & getBoundaryRhsFE()
Get boundary right-hand side finite element.
Simple interface for fast problem set-up.
MoFEMErrorCode addDomainField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
MoFEMErrorCode addBoundaryField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on boundary.
MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string row_field, const std::string col_field) const
Add empty block to problem.
MoFEMErrorCode getOptions()
get options
MoFEMErrorCode getDM(DM *dm)
Get DM.
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.