12#define BOOST_MATH_GAUSS_NO_COMPUTE_ON_DEMAND
16static char help[] =
"...\n\n";
41const double v =
c /
n;
64#include <boost/math/quadrature/gauss_kronrod.hpp>
65using namespace boost::math::quadrature;
113 OpError(boost::shared_ptr<CommonData> &common_data_ptr)
120 if (
const size_t nb_dofs = data.
getIndices().size()) {
122 const int nb_integration_pts = getGaussPts().size2();
123 auto t_w = getFTensor0IntegrationWeight();
125 auto t_coords = getFTensor1CoordsAtGaussPts();
131 const double volume = getMeasure();
135 for (
int gg = 0; gg != nb_integration_pts; ++gg) {
137 const double alpha = t_w * volume;
139 t_coords(0), t_coords(1), t_coords(2));
141 error += alpha * pow(diff, 2);
143 for (
size_t r = 0; r != nb_dofs; ++r) {
144 nf[r] += alpha * t_row_base * diff;
208 MOFEM_LOG(
"INITIAL", Sev::inform) <<
"Refractive index: " <<
n;
209 MOFEM_LOG(
"INITIAL", Sev::inform) <<
"Speed of light (cm/ns): " <<
c;
211 <<
"Phase velocity in medium (cm/ns): " <<
v;
213 <<
"Absorption coefficient (cm^-1): " <<
mu_a;
215 <<
"Scattering coefficient (cm^-1): " <<
mu_sp;
216 MOFEM_LOG(
"INITIAL", Sev::inform) <<
"Diffusion coefficient D : " <<
D;
224 MOFEM_LOG(
"INITIAL", Sev::inform) <<
"Approximation order: " <<
order;
267 commonDataPtr = boost::make_shared<PhotonDiffusion::CommonData>();
271 commonDataPtr->uAtPtsPtr = boost::make_shared<VectorDouble>();
288 Range boundary_faces;
290 std::string entity_name = it->getName();
291 if (entity_name.compare(0, 3,
"INT") == 0) {
293 boundary_faces,
true);
297 if (boundary_faces.empty()) {
299 std::string entity_name = it->getName();
301 boundary_faces,
true);
308 boundary_faces, 1,
false, boundary_ents, moab::Interface::UNION);
310 Range boundary_verts;
312 boundary_faces, 0,
false, boundary_verts, moab::Interface::UNION);
314 boundary_faces.merge(boundary_verts);
315 boundary_faces.merge(boundary_ents);
320 EntityHandle meshset;
327 simple->getProblemName(),
"PHOTON_FLUENCE_RATE", boundary_faces);
342 auto set_domain = [&]() {
348 "PHOTON_FLUENCE_RATE",
"PHOTON_FLUENCE_RATE",
349 [](
const double,
const double,
const double) {
return 1; }));
359 auto set_boundary = [&]() {
378 auto solver = pipeline_mng->createKSP();
380 CHKERR KSPSetFromOptions(solver);
382 auto dm =
simple->getDM();
386 MOFEM_LOG(
"INITIAL", Sev::inform) <<
"Solver start";
388 CHKERR VecGhostUpdateBegin(X, INSERT_VALUES, SCATTER_FORWARD);
389 CHKERR VecGhostUpdateEnd(X, INSERT_VALUES, SCATTER_FORWARD);
393 <<
"writing vector in binary to " <<
out_file_name <<
" ...";
395 PetscViewerBinaryOpen(PETSC_COMM_WORLD,
out_file_name, FILE_MODE_WRITE,
398 PetscViewerDestroy(&viewer);
400 MOFEM_LOG(
"INITIAL", Sev::inform) <<
"Solver done";
408 auto post_proc_fe = boost::make_shared<PostProcEle>(
mField);
410 auto u_ptr = boost::make_shared<VectorDouble>();
411 post_proc_fe->getOpPtrVector().push_back(
416 post_proc_fe->getOpPtrVector().push_back(
420 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
422 {{
"PHOTON_FLUENCE_RATE", u_ptr}},
433 CHKERR pipeline_mng->loopFiniteElementsPostProc();
434 CHKERR post_proc_fe->writeFile(
"out_initial.h5m");
479 PetscPrintf(PETSC_COMM_SELF,
"Error %6.4e Vec norm %6.4e\n",
480 std::sqrt(array[0]), nrm2);
482 constexpr double eps = 1e-8;
485 "Not converged solution");
490int main(
int argc,
char *argv[]) {
493 const char param_file[] =
"param_file.petsc";
497 auto core_log = logging::core::get();
506 DMType dm_name =
"DMMOFEM";
510 moab::Core mb_instance;
511 moab::Interface &moab = mb_instance;
void simple(double P1[], double P2[], double P3[], double c[], const int N)
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, FIELD_DIM > OpDomainSource
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, FIELD_DIM > OpDomainMass
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#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.
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.
MoFEMErrorCode loopFiniteElements(SmartPetscObj< DM > dm=nullptr)
Iterate finite elements.
boost::ptr_deque< UserDataOperator > & getOpDomainLhsPipeline()
Get the Op Domain Lhs Pipeline object.
boost::ptr_deque< UserDataOperator > & getOpDomainRhsPipeline()
Get the Op Domain Rhs Pipeline object.
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.
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
FTensor::Index< 'i', SPACE_DIM > i
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpGradGrad< 1, 1, SPACE_DIM > OpDomainGradGrad
double mu_sp
scattering coefficient (cm^-1)
double flux_magnitude
impulse magnitude
const int kronrod_points
This has been tested and gives the same result for any number of points. Increasing the number of poi...
constexpr int SPACE_DIM
[Define dimension]
const double c
speed of light (cm/ns)
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpGradTimesTensor< 1, 1, SPACE_DIM > OpDomainGradTimesVec
double mu_a
absorption coefficient (cm^-1)
const double v
phase velocity of light in medium (cm/ns)
const double n
refractive index of diffusive medium
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< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
static auto getFTensor0FromVec(V &data)
Get tensor rank 0 (scalar) form data vector.
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.
double sourceFunctionEval(const double x, const double y, const double z, const double beam_radius, const double beam_centre_x, const double beam_centre_y, const double slab_thickness, const double mu_a, const double mu_sp, const double flux_magnitude, double initial_time, const double v, const double D)
Pulse is infinitely short.
double mu_sp
scattering coefficient (cm^-1)
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, 1 > OpDomainMass
double flux_magnitude
impulse magnitude
const int kronrod_points
This has been tested and gives the same result for any number of points. Increasing the number of poi...
const double c
speed of light (cm/ns)
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, 1 > OpDomainSource
double mu_a
absorption coefficient (cm^-1)
const double v
phase velocity of light in medium (cm/ns)
const double n
refractive index of diffusive medium
static constexpr int approx_order
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpBaseTimesScalar< 1 > OpDomainTimesScalarField
Add operators pushing bases from local to physical configuration.
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() 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.
Data on single entity (This is passed as argument to DataOperator::doWork)
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
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.
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 > & getDomainPostProcFE()
Get domain postprocessing finite element.
MoFEMErrorCode setDomainRhsIntegrationRule(RuleHookFun rule)
Set integration rule for domain right-hand side finite element.
MoFEMErrorCode setBoundaryLhsIntegrationRule(RuleHookFun rule)
Set integration rule for boundary left-hand side finite element.
MoFEMErrorCode setBoundaryRhsIntegrationRule(RuleHookFun rule)
Set integration rule for boundary right-hand side finite element.
MoFEMErrorCode setDomainLhsIntegrationRule(RuleHookFun rule)
Set integration rule for domain left-hand side finite element.
Problem manager is used to build and partition problems.
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.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Volume finite element base.
boost::shared_ptr< VectorDouble > uAtPtsPtr
SmartPetscObj< Vec > L2Vec
SmartPetscObj< Vec > resVec
OpError(boost::shared_ptr< CommonData > &common_data_ptr)
boost::shared_ptr< CommonData > commonDataPtr
MoFEMErrorCode doWork(int side, EntityType type, EntData &data)
MoFEMErrorCode assembleSystem()
[interior_boundary]
MoFEMErrorCode solveSystem()
[assembleSystem]
MoFEM::Interface & mField
MoFEMErrorCode readMesh()
[sourceFunction]
MoFEMErrorCode outputResults()
[solveSystem]
MoFEMErrorCode initialCondition()
PhotonDiffusion(MoFEM::Interface &m_field)
MoFEMErrorCode checkResults()
[runProgram]
MoFEMErrorCode runProgram()
[runProgram]
MoFEMErrorCode createCommonData()
MoFEMErrorCode boundaryCondition()
[interior_boundary]
static double sourceFunction(const double x, const double y, const double z)
MoFEMErrorCode setupProblem()
boost::shared_ptr< CommonData > commonDataPtr