8#ifndef EXECUTABLE_DIMENSION
9 #define EXECUTABLE_DIMENSION 2
43double hbar = 1.054571817e-34;
44double m0 = 9.1093837015e-31;
47double q = 1.602176634e-19;
53static char help[] =
"...\n\n";
155 auto calculate_Hamiltonian = [&]() {
157 pipeline_mng->getDomainLhsFE().reset();
160 pipeline_mng->getOpDomainLhsPipeline(), {H1});
161 pipeline_mng->getOpDomainLhsPipeline().push_back(
163 pipeline_mng->getOpDomainLhsPipeline().push_back(
170 pipeline_mng->getDomainLhsFE()->B =
H;
172 CHKERR pipeline_mng->loopFiniteElements();
173 CHKERR MatAssemblyBegin(
H, MAT_FINAL_ASSEMBLY);
174 CHKERR MatAssemblyEnd(
H, MAT_FINAL_ASSEMBLY);
178 auto calculate_mass_matrix = [&]() {
180 pipeline_mng->getDomainLhsFE().reset();
183 pipeline_mng->getOpDomainLhsPipeline(), {H1});
184 pipeline_mng->getOpDomainLhsPipeline().push_back(
192 pipeline_mng->getDomainLhsFE()->B =
M;
193 CHKERR pipeline_mng->loopFiniteElements();
194 CHKERR MatAssemblyBegin(
M, MAT_FINAL_ASSEMBLY);
195 CHKERR MatAssemblyEnd(
M, MAT_FINAL_ASSEMBLY);
199 CHKERR calculate_Hamiltonian();
200 CHKERR calculate_mass_matrix();
210 auto create_eps = [](MPI_Comm comm) {
216 auto setup_eps = [&]() {
219 CHKERR EPSSetWhichEigenpairs(
eps, EPS_SMALLEST_MAGNITUDE);
222 EPSSetDimensions(
eps, nev, PETSC_DEFAULT, PETSC_DEFAULT);
226 auto print_info = [&]() {
231 PetscInt nev, maxit, its;
235 " Number of iterations of the method: %d", its);
239 CHKERR EPSGetDimensions(
eps, &nev, NULL, NULL);
240 MOFEM_LOG_C(
"EXAMPLE", Sev::inform,
" Number of requested eigenvalues: %d",
244 " Stopping condition: tol=%.4g, maxit=%d", (
double)
tol, maxit);
272 auto post_proc_fe = boost::make_shared<PostProcEle>(
mField);
274 auto phi_ptr = boost::make_shared<VectorDouble>();
275 auto square_ptr = boost::make_shared<VectorDouble>();
277 post_proc_fe->getOpPtrVector().push_back(
279 post_proc_fe->getOpPtrVector().push_back(
new OpSquare(
285 post_proc_fe->getOpPtrVector().push_back(
287 new OpPPMap(post_proc_fe->getPostProcMesh(),
288 post_proc_fe->getMapGaussPts(),
300 pipeline_mng->getDomainRhsFE() = post_proc_fe;
302 auto dm =
simple->getDM();
305 PetscInt nev, nconv, n_output = 0;
306 CHKERR EPSGetDimensions(
eps, &nev, PETSC_NULLPTR, PETSC_NULLPTR);
308 n_output = std::min(nconv, nev);
311 " Only %" PetscInt_FMT
" of %" PetscInt_FMT
312 " requested eigenpairs converged",
315 PetscScalar eigr, eigi;
316 for (PetscInt nn = 0; nn < n_output; nn++) {
317 CHKERR EPSGetEigenpair(
eps, nn, &eigr, &eigi,
D, PETSC_NULLPTR);
318 CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
319 CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
321 " Eigenpair = %" PetscInt_FMT
" Eigen Energy = %.8g eV", nn,
324 CHKERR pipeline_mng->loopFiniteElements();
325 post_proc_fe->writeFile(
"out_schrod_" +
326 boost::lexical_cast<std::string>(nn) +
".h5m");
336 PetscBool test_flg = PETSC_FALSE;
344 "No eigenpairs converged");
346 PetscScalar eigr, eigi;
347 CHKERR EPSGetEigenpair(
eps, 0, &eigr, &eigi, PETSC_NULLPTR, PETSC_NULLPTR);
348 constexpr double regression_value =
350 if (fabs(eigr /
q - regression_value) > 1e-3) {
351 PetscPrintf(PETSC_COMM_WORLD,
352 "Calculated ground energy: %.4g, expected %.4g\n",
353 (
double)eigr /
q, regression_value);
355 "Regression test faileed; wrong eigen value. Try higher order or "
363int main(
int argc,
char *argv[]) {
366 const char param_file[] =
"param_file.petsc";
367 SlepcInitialize(&argc, &argv, param_file,
help);
371 auto core_log = logging::core::get();
380 DMType dm_name =
"DMMOFEM";
385 moab::Core mb_instance;
386 moab::Interface &moab = mb_instance;
#define MOFEM_LOG_C(channel, severity, format,...)
void simple(double P1[], double P2[], double P3[], double c[], const int N)
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, FIELD_DIM > OpDomainMass
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_BERNSTEIN_BEZIER_BASE
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M)
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true, bool is_distributed_mesh=true)
Remove DOFs from problem based on block entities.
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpGradGrad< 1, 1, SPACE_DIM > OpDomainGradGrad
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 PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
SmartPetscObj< Mat > matDuplicate(Mat mat, MatDuplicateOption op)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
static constexpr int approx_order
#define EXECUTABLE_DIMENSION
double hbar
[Physical constants and parameters]
int order
[Physical constants and parameters]
Calculate the square of wave function.
MoFEMErrorCode boundaryCondition()
MoFEMErrorCode assembleSystem()
MoFEMErrorCode readMesh()
MoFEMErrorCode checkResults()
MoFEMErrorCode solveSystem()
Example(MoFEM::Interface &m_field)
MoFEMErrorCode runProblem()
MoFEM::Interface & mField
Reference to MoFEM interface.
MoFEMErrorCode setupProblem()
MoFEMErrorCode outputResults()
Add operators pushing bases from local to physical configuration.
Boundary condition manager for finite element problem setup.
Template specialization for scalar field boundary conditions.
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.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
Specialization for double precision scalar field values calculation.
Post post-proc data at points from hash maps.
std::map< std::string, ScalarDataPtr > DataMapVec
std::map< std::string, boost::shared_ptr< MatrixDouble > > DataMapMat
PipelineManager interface.
boost::shared_ptr< FEMethod > & getDomainLhsFE()
Get domain left-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 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.
const std::string getProblemName() const
Get the Problem Name.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Volume finite element base.
[Calculate square of wave function]
#define EXECUTABLE_DIMENSION