|
| v0.14.0
|
Go to the documentation of this file.
31 using namespace MoFEM;
33 static char help[] =
"...\n\n";
35 int main(
int argc,
char *argv[]) {
44 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
46 boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD,
false);
49 new ParallelComm(&moab, moab_comm_wrap->get_comm());
54 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"Lorenz force configure",
56 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"solution.h5m",
58 ierr = PetscOptionsEnd();
76 CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
77 CHKERR DMSetType(dm,
"DMMOFEM");
80 CHKERR DMSetFromOptions(dm);
93 struct MyOpDebug :
public VolOp {
95 boost::shared_ptr<MatrixDouble> B;
96 MyOpDebug(decltype(B) b) :
VolOp(
"MAGNETIC_POTENTIAL", OPROW), B(b) {}
101 if (
type == MBEDGE && side == 0) {
102 std::cout <<
"found " << (*B) << endl;
110 const double dist = 1e-12;
111 const int nb_random_points = 5000;
112 const int nb_steps = 10000;
113 const int mod_step = 10;
114 const double dt = 1e-5;
115 const double velocity_scale = 0.1;
116 const double magnetic_field_scale = 1;
117 const double scale_box = 0.5;
124 auto vol_ele = data_at_pts->feMethodPtr.lock();
127 "Pointer to element does not exists");
128 auto get_rule = [&](
int order_row,
int order_col,
int order_data) {
143 CHKERR data_at_pts->treePtr->get_bounding_box(box);
145 const double bMin = box.bMin[0];
146 const double bMax = box.bMax[0];
148 auto create_vertices = [nb_random_points, bMin, bMax,
150 auto &arrays_coord) {
152 ReadUtilIface *iface;
154 CHKERR moab.query_interface(iface);
155 CHKERR iface->get_node_coords(3, nb_random_points, 0, startv,
158 arrays_coord[0], arrays_coord[1], arrays_coord[2]};
160 verts =
Range(startv, startv + nb_random_points - 1);
161 for (
int n = 0;
n != nb_random_points; ++
n) {
163 for (
auto ii : {1, 2}) {
164 t_coords(ii) = scale_box * (bMax - bMin) *
165 (std::rand() /
static_cast<double>(RAND_MAX)) -
173 auto set_positions = [nb_random_points,
dt, velocity_scale](
177 arrays_coord[0], arrays_coord[1], arrays_coord[2]};
179 &init_pos(0, 0), &init_pos(1, 0), &init_pos(2, 0)};
181 for (
int n = 0;
n != nb_random_points; ++
n) {
184 for (
auto ii : {0, 1, 2})
185 t_velocity(ii) = (rand() /
static_cast<double>(RAND_MAX) - 0.5);
186 t_velocity(
i) /= std::sqrt(t_velocity(
i) * t_velocity(
i));
187 t_init_coords(
i) = t_coords(
i) +
dt * velocity_scale * t_velocity(
i);
197 vector<double *> arrays_coord;
199 CHKERR create_vertices(moab_charged_partices, verts, arrays_coord);
200 auto init_positions = set_positions(moab, arrays_coord);
202 auto get_t_coords = [&]() {
204 arrays_coord[0], arrays_coord[1], arrays_coord[2]);
207 auto get_t_init_coords = [&]() {
209 &init_positions(0, 0), &init_positions(1, 0), &init_positions(2, 0));
212 auto calc_rhs = [&](
auto &t_p,
auto &t_init_p,
auto &t_B) {
217 t_rhs(
k) = (2 * t_p(
k) - t_init_p(
k)) /
dt -
222 auto calc_lhs = [&](
auto &t_B) {
228 for (
auto ii : {0, 1, 2})
229 t_lhs(ii, ii) += 1 /
dt;
244 auto is_out = [&](
auto &t_p) {
245 for (
int i : {0, 1, 2})
248 }
else if (t_p(
i) < bMin) {
254 auto cache_ptr = boost::make_shared<CacheTuple>();
257 auto calc_position = [&]() {
258 auto t_p = get_t_coords();
259 auto t_init_p = get_t_init_coords();
263 for (
int n = 0;
n != nb_random_points; ++
n) {
271 std::array<double, 3> point = {t_p(0), t_p(1), t_p(2)};
272 data_at_pts->setEvalPoints(point.data(), 1);
275 point.data(),
dist, prb_ptr->
getName(),
"MAGNETIC", data_at_pts,
282 for (
int ii : {0, 1, 2})
283 t_B(ii) = (*B)(ii, 0);
287 t_B(
i) *= magnetic_field_scale * 0.5;
289 auto t_rhs = calc_rhs(t_p, t_init_p, t_B);
290 auto t_lhs = calc_lhs(t_B);
297 t_init_p(
i) = t_p(
i);
298 t_p(
i) = t_inv_lhs(
i,
j) * t_rhs(
j);
307 for (
int t = 0;
t != nb_steps; ++
t) {
309 std::string print_step =
310 "Step : " + boost::lexical_cast<std::string>(
t) +
"\r";
311 std::cout << print_step << std::flush;
315 if ((
t % mod_step) == 0) {
317 CHKERR moab_charged_partices.write_file(
318 (
"step_" + boost::lexical_cast<std::string>(
t / mod_step) +
".vtk")
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Data on single entity (This is passed as argument to DataOperator::doWork)
#define MYPCOMM_INDEX
default communicator number PCOMM
RuleHookFun getRuleHook
Hook to get rule.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
virtual int get_comm_rank() const =0
const VectorDouble & getFieldData() const
get dofs values
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
constexpr std::enable_if<(Dim0<=2 &&Dim1<=2), Tensor2_Expr< Levi_Civita< T >, T, Dim0, Dim1, i, j > >::type levi_civita(const Index< i, Dim0 > &, const Index< j, Dim1 > &)
levi_civita functions to make for easy adhoc use
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Deprecated interface functions.
MoFEMErrorCode invertTensor3by3(ublas::matrix< T, L, A > &jac_data, ublas::vector< T, A > &det_data, ublas::matrix< T, L, A > &inv_jac_data)
Calculate inverse of tensor rank 2 at integration points.
DeprecatedCoreInterface Interface
MoFEMErrorCode buildTree3D(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
Calculate curl of vector field.
#define CHKERR
Inline error check.
implementation of Data Operators for Forces and Sources
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
Field evaluator interface.
MoFEMErrorCode evalFEAtThePoint3D(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetPtsData > data_ptr, int lower_rank, int upper_rank, boost::shared_ptr< CacheTuple > cache_ptr, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
Evaluate field at artbitray position.
int main(int argc, char *argv[])
friend class UserDataOperator
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
virtual MoFEMErrorCode cache_problem_entities(const std::string prb_name, CacheTupleWeakPtr cache_ptr)=0
Cache variables.
constexpr double t
plate stiffness
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
Volume finite element base.
FTensor::Index< 'i', SPACE_DIM > i
VolEle::UserDataOperator VolOp
boost::shared_ptr< SPD > getData(const double *ptr=nullptr, const int nb_eval_points=0, const double eps=1e-12, VERBOSITY_LEVELS verb=QUIET)
Get the Data object.
static auto determinantTensor3by3(T &t)
Calculate the determinant of a 3x3 matrix or a tensor of rank 2.
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
#define CATCH_ERRORS
Catch errors.
FTensor::Index< 'j', 3 > j
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
boost::ptr_deque< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
@ MOFEM_DATA_INCONSISTENCY
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
keeps basic data about problem
FTensor::Index< 'k', 3 > k
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...