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_NULL);
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);
413 auto flux_ptr = boost::make_shared<MatrixDouble>();
414 pipeline_mng->getOpBoundaryRhsPipeline().push_back(
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);
446 auto det_ptr = boost::make_shared<VectorDouble>();
447 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
448 auto jac_ptr = boost::make_shared<MatrixDouble>();
450 pipeline_mng->getOpDomainLhsPipeline().push_back(
452 pipeline_mng->getOpDomainLhsPipeline().push_back(
455 pipeline_mng->getOpDomainLhsPipeline().push_back(
457 pipeline_mng->getOpDomainLhsPipeline().push_back(
461 pipeline_mng->getOpDomainLhsPipeline().push_back(
463 auto unity = []() {
return 1; };
464 pipeline_mng->getOpDomainLhsPipeline().push_back(
465 new OpHdivU(
"S",
"PHI", unity,
true));
468 pipeline_mng->getOpDomainRhsPipeline().push_back(
483 CHKERR KSPSetFromOptions(solver);
488 CHKERR KSPSolve(solver,
F, iD);
489 CHKERR VecGhostUpdateBegin(iD, INSERT_VALUES, SCATTER_FORWARD);
490 CHKERR VecGhostUpdateEnd(iD, INSERT_VALUES, SCATTER_FORWARD);
493 double i_lambda_flux;
497 <<
"iD flux " << std::scientific << i_lambda_flux;
513 auto post_proc_fe = boost::make_shared<PostProcEle>(
mField);
514 auto jac_ptr = boost::make_shared<MatrixDouble>();
515 post_proc_fe->getOpPtrVector().push_back(
518 post_proc_fe->getOpPtrVector().push_back(
521 auto s_ptr = boost::make_shared<VectorDouble>();
522 auto phi_ptr = boost::make_shared<MatrixDouble>();
523 post_proc_fe->getOpPtrVector().push_back(
525 post_proc_fe->getOpPtrVector().push_back(
530 post_proc_fe->getOpPtrVector().push_back(
532 new OpPPMap(post_proc_fe->getPostProcMesh(),
533 post_proc_fe->getMapGaussPts(),
553 CHKERR post_proc_fe->writeFile(
"out_" + boost::lexical_cast<std::string>(
i) +
559int main(
int argc,
char *argv[]) {
568 DMType dm_name =
"DMMOFEM";
573 moab::Core mb_instance;
574 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.
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, SPACE_DIM > OpMass
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
OpSetInvJacHcurlFaceImpl< 2 > OpSetInvJacHcurlFace
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
OpCalculateHOJacForFaceImpl< 2 > OpCalculateHOJacForFace
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
OpSetContravariantPiolaTransformOnFace2DImpl< 2 > OpSetContravariantPiolaTransformOnFace2D
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
OpBaseImpl< PETSC, EdgeEleOp > OpBase
FTensor::Index< 'i', 3 > i
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
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
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.
Get value at integration points for scalar field.
Make Hdiv space from Hcurl space in 2d.
Post post-proc data at points from hash maps.
std::map< std::string, boost::shared_ptr< VectorDouble > > DataMapVec
std::map< std::string, boost::shared_ptr< MatrixDouble > > DataMapMat
Modify integration weights on face to take in account higher-order geometry.
PipelineManager interface.
boost::shared_ptr< FEMethod > & getDomainRhsFE()
boost::shared_ptr< FEMethod > & getDomainLhsFE()
boost::shared_ptr< FEMethod > & getBoundaryRhsFE()
Simple interface for fast problem set-up.
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
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 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 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 setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 3, SPACE_DIM > OpHdivHdiv
[Linear elastic problem]