14 : cOre(const_cast<
Core &>(core)) {}
25 std::vector<RandomFieldData> random_fields,
26 boost::shared_ptr<Range> ents_ptr) {
32 auto get_random_number = [](
auto &range) {
33 const auto r =
static_cast<double>(std::rand()) / RAND_MAX;
34 return range[0] + r * (range[1] - range[0]);
43 for (
auto &rf : random_fields) {
46 <<
"Set random field " << rf.first <<
" " <<
static_cast<int>(field_id);
49 auto lo = prb_ptr->getNumeredRowDofsPtr()->lower_bound(
51 const auto hi = prb_ptr->getNumeredRowDofsPtr()->upper_bound(
53 for (; lo != hi; ++lo) {
54 const auto idx = (*lo)->getPetscLocalDofIdx();
55 array[idx] = get_random_number(rf.second);
58 for (
auto pit = ents_ptr->const_pair_begin();
59 pit != ents_ptr->const_pair_end(); ++pit) {
61 prb_ptr->getNumeredRowDofsPtr()->get<
Unique_mi_tag>().lower_bound(
64 prb_ptr->getNumeredRowDofsPtr()->get<
Unique_mi_tag>().upper_bound(
66 for (; lo != hi; ++lo) {
67 const auto idx = (*lo)->getPetscLocalDofIdx();
68 array[idx] = get_random_number(rf.second);
74 CHKERR VecRestoreArray(
v, &array);
76 CHKERR VecGhostUpdateBegin(
v, INSERT_VALUES, SCATTER_FORWARD);
77 CHKERR VecGhostUpdateEnd(
v, INSERT_VALUES, SCATTER_FORWARD);
84 boost::shared_ptr<FEMethod> pipeline,
92 pipeline->ts_t = time;
93 pipeline->ts_dt = delta_t;
95 auto [
v,
a] =
setPipelineX(pipeline, x, delta_x, delta2_x, delta_t);
103 "Run assemble pipeline");
121 boost::shared_ptr<FEMethod> pipeline,
132 pipeline->ts_t = time;
134 pipeline->ts_dt = delta_t;
135 pipeline->ts_a = 1. / delta_t;
136 pipeline->ts_aa = 1. / pow(delta_t, 2);
138 auto [
v,
a] =
setPipelineX(pipeline, x, delta_x, delta2_x, delta_t);
146 "Run assemble pipeline");
160 auto axpy = [&](
auto v0,
auto diff_v,
auto eps) {
162 if (v0.use_count()) {
176 axpy(x, diff_x, -
eps),
178 axpy(delta_x, diff_x, -
eps),
180 axpy(delta2_x, diff_x, -
eps),
182 time, delta_t, cache_ptr);
186 axpy(x, diff_x,
eps),
188 axpy(delta_x, diff_x,
eps),
190 axpy(delta2_x, diff_x,
eps),
192 time, delta_t, cache_ptr);
194 auto calculate_derivative = [
eps](
auto fm1,
auto fp1) {
196 VecGetLocalSize(fp1, &size);
197 VecAXPY(fp1, -1, fm1);
199 VecGetArray(fp1, &array);
200 for (
int j = 0;
j != size; ++
j) {
203 VecRestoreArray(fp1, &array);
207 return calculate_derivative(fm1, fp1);
212 boost::shared_ptr<FEMethod> pipeline_rhs,
219 dm, fe_name, pipeline_rhs, x, delta_x, delta2_x, diff_x, time, delta_t,
222 auto m =
assembleMat(dm, fe_name, pipeline_lhs, x, delta_x, delta2_x, time,
248 VecCopy(delta_x, x_t);
249 VecScale(x_t, 1. / delta_t);
257 pipeline->x_t = PETSC_NULL;
264 VecCopy(delta2_x, x_tt);
265 VecScale(x_tt, 1. / pow(delta_t, 2));
270 pipeline->x_tt = x_tt;
273 pipeline->x_tt = PETSC_NULL;
276 return std::make_pair(x_t, x_tt);
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define CHKERR
Inline error check.
FTensor::Index< 'm', SPACE_DIM > m
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
auto createDMVector(DM dm)
Get smart vector from DM.
auto createDMMatrix(DM dm)
Get smart matrix from DM.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'j', 3 > j
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
auto getProblemPtr(DM dm)
get problem pointer from DM
boost::weak_ptr< CacheTuple > CacheTupleWeakPtr
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
Deprecated interface functions.
static UId getLoFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
static UId getHiFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
Calculate directional derivative of the right hand side and compare it with tangent matrix derivative...
SmartPetscObj< Mat > assembleMat(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, double time, double delta_t, CacheTupleWeakPtr cache_ptr)
Assemble the left hand side vector.
SmartPetscObj< Vec > setRandomFields(SmartPetscObj< DM > dm, std::vector< RandomFieldData > random_fields, boost::shared_ptr< Range > ents=nullptr)
Generate random fileds.
SmartPetscObj< Vec > checkCentralFiniteDifference(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline_rhs, boost::shared_ptr< FEMethod > pipeline_lhs, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, SmartPetscObj< Vec > diff_x, double time, double delta_t, double eps, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Check consistency between directional derivative with matrix.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
OperatorsTester(const MoFEM::Core &core)
SmartPetscObj< Vec > assembleVec(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, double time, double delta_t, CacheTupleWeakPtr cache_ptr)
Assemble the right hand side vector.
std::pair< SmartPetscObj< Vec >, SmartPetscObj< Vec > > setPipelineX(boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, double delta_t)
Set vectors, x, x_t, and x_tt to finite element instance.
SmartPetscObj< Vec > directionalCentralFiniteDifference(SmartPetscObj< DM > dm, std::string fe_name, boost::shared_ptr< FEMethod > pipeline, SmartPetscObj< Vec > x, SmartPetscObj< Vec > delta_x, SmartPetscObj< Vec > delta2_x, SmartPetscObj< Vec > diff_x, double time, double delta_t, double eps, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Calculate directional directive using finite difference.
static constexpr Switches CtxSetA
static constexpr Switches CtxSetF
static constexpr Switches CtxSetB
static constexpr Switches CtxSetTime
intrusive_ptr for managing petsc objects
base class for all interface classes