Non-linear elastic dynamics.
static char help[] =
"...\n\n";
std::map<int, NonlinearElasticElement::BlockData> &setOfBlocks;
&feElasticEnergy;
&feKineticEnergy;
bool iNit;
int pRT;
int *step;
std::map<int, NonlinearElasticElement::BlockData> &set_of_blocks,
:
FEMethod(), mField(m_field), postProc(m_field),
setOfBlocks(set_of_blocks), feElasticEnergy(fe_elastic_energy),
feKineticEnergy(fe_kinetic_energy), iNit(false) {
double def_t_val = 0;
Tag th_step;
"_TsStep_", 1, MB_TYPE_INTEGER, th_step,
MB_TAG_CREAT | MB_TAG_EXCL | MB_TAG_MESH, &def_t_val);
if (
rval == MB_ALREADY_ALLOCATED) {
(const void **)&step));
} else {
&def_t_val));
(const void **)&step));
}
PetscBool flg = PETSC_TRUE;
"-my_output_prt", &pRT, &flg),
"Can not get option");
if (flg != PETSC_TRUE) {
pRT = 10;
}
}
if (!iNit) {
false);
std::map<int, NonlinearElasticElement::BlockData>::iterator sit =
setOfBlocks.begin();
for (; sit != setOfBlocks.end(); sit++) {
}
iNit = true;
}
if ((*step) % pRT == 0) {
std::ostringstream sss;
sss << "out_values_" << (*step) << ".h5m";
}
feKineticEnergy);
double T = feKineticEnergy.
eNergy;
"DYNAMIC", Sev::inform,
"%d Time %3.2e Elastic energy %3.2e Kinetic Energy %3.2e Total %3.2e\n",
ts_step, ts_t,
E, T,
E + T);
}
}
}
};
double *time;
int *step;
int pRT;
double def_t_val = 0;
Tag th_time;
"_TsTime_", 1, MB_TYPE_DOUBLE, th_time,
MB_TAG_CREAT | MB_TAG_EXCL | MB_TAG_MESH, &def_t_val);
if (
rval == MB_ALREADY_ALLOCATED) {
rval = m_field.
get_moab().tag_get_by_ptr(th_time, &root_meshset, 1,
(const void **)&time);
ierr = TSSetTime(ts, *time);
CHKERRABORT(PETSC_COMM_WORLD,
ierr);
} else {
rval = m_field.
get_moab().tag_set_data(th_time, &root_meshset, 1,
&def_t_val);
rval = m_field.
get_moab().tag_get_by_ptr(th_time, &root_meshset, 1,
(const void **)&time);
}
Tag th_step;
"_TsStep_", 1, MB_TYPE_INTEGER, th_step,
MB_TAG_CREAT | MB_TAG_EXCL | MB_TAG_MESH, &def_t_val);
if (
rval == MB_ALREADY_ALLOCATED) {
rval = m_field.
get_moab().tag_get_by_ptr(th_step, &root_meshset, 1,
(const void **)&step);
} else {
rval = m_field.
get_moab().tag_set_data(th_step, &root_meshset, 1,
&def_t_val);
rval = m_field.
get_moab().tag_get_by_ptr(th_step, &root_meshset, 1,
(const void **)&step);
}
PetscBool flg = PETSC_TRUE;
&flg);
CHKERRABORT(PETSC_COMM_WORLD,
ierr);
if (flg != PETSC_TRUE) {
pRT = 10;
}
}
(*time) = ts_t;
(*step)++;
}
}
}
};
#include <TimeForceScale.hpp>
int main(
int argc,
char *argv[]) {
const string default_options = "-ksp_type fgmres \n"
"-pc_type lu \n"
"-pc_factor_mat_solver_type mumps \n"
"-mat_mumps_icntl_20 0 \n"
"-ksp_atol 1e-10 \n"
"-ksp_rtol 1e-10 \n"
"-snes_monitor \n"
"-snes_type newtonls \n"
"-snes_linesearch_type basic \n"
"-snes_max_it 100 \n"
"-snes_atol 1e-7 \n"
"-snes_rtol 1e-7 \n"
"-ts_monitor \n"
"-ts_type alpha \n";
string param_file = "param_file.petsc";
if (!static_cast<bool>(ifstream(param_file))) {
std::ofstream file(param_file.c_str(), std::ios::ate);
if (file.is_open()) {
file << default_options;
file.close();
}
}
auto core_log = logging::core::get();
core_log->add_sink(
try {
ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
auto moab_comm_wrap =
boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD, false);
if (pcomm == NULL)
pcomm = new ParallelComm(&moab, moab_comm_wrap->get_comm());
PetscBool is_partitioned = PETSC_FALSE;
PetscBool linear = PETSC_TRUE;
PetscInt disp_order = 1;
PetscInt vel_order = 1;
PetscBool is_solve_at_time_zero = PETSC_FALSE;
auto read_command_line_parameters = [&]() {
PetscBool flg = PETSC_TRUE;
if (flg != PETSC_TRUE)
SETERRQ(PETSC_COMM_SELF, 1, "Error -my_file (mesh file needed)");
&is_partitioned, &flg);
PETSC_NULL);
enum bases { LEGENDRE, LOBATTO, BERNSTEIN_BEZIER, LASBASETOP };
const char *list_bases[] = {"legendre", "lobatto", "bernstein_bezier"};
PetscInt choice_base_value = BERNSTEIN_BEZIER;
LASBASETOP, &choice_base_value, PETSC_NULL);
if (choice_base_value == LEGENDRE)
else if (choice_base_value == LOBATTO)
else if (choice_base_value == BERNSTEIN_BEZIER)
&disp_order, &flg);
if (flg != PETSC_TRUE)
disp_order = 1;
&vel_order, &flg);
if (flg != PETSC_TRUE)
vel_order = disp_order;
"-my_solve_at_time_zero",
&is_solve_at_time_zero, &flg);
};
auto read_mesh = [&]() {
if (is_partitioned == PETSC_TRUE) {
const char *option;
option = "PARALLEL=BCAST_DELETE;"
"PARALLEL_RESOLVE_SHARED_ENTS;"
"PARTITION=PARALLEL_PARTITION;";
} else {
const char *option;
option = "";
}
};
CHKERR read_command_line_parameters();
bit_level0.set(0);
CHKERR moab.create_meshset(MESHSET_SET, meshset_level0);
0, 3, bit_level0);
bool check_if_spatial_field_exist = m_field.
check_field(
"DISPLACEMENT");
else
fluid_pressure_fe.addNeumannFluidPressureBCElements("DISPLACEMENT");
false, false);
fluid_pressure_fe.setNeumannFluidPressureFiniteElementOperators(
"DISPLACEMENT", PETSC_NULL, false, true);
else
disp_order);
else
else
CHKERR elastic_materials.setBlocks(elastic.setOfBlocks);
CHKERR elastic.addElement(
"ELASTIC",
"DISPLACEMENT");
false, false);
false, false);
false, false, false);
CHKERR elastic.setOperators(
"DISPLACEMENT",
"MESH_NODE_POSITIONS",
false,
true);
CHKERR elastic_materials.setBlocks(inertia.setOfBlocks);
CHKERR inertia.addConvectiveMassElement(
"MASS_ELEMENT",
"VELOCITY",
"DISPLACEMENT");
CHKERR inertia.addVelocityElement(
"VELOCITY_ELEMENT",
"VELOCITY",
"DISPLACEMENT");
{
string name = "-my_accelerogram";
char time_file_name[255];
PetscBool flg;
time_file_name, 255, &flg);
if (flg == PETSC_TRUE) {
}
}
CHKERR elastic_materials.setBlocks(damper.blockMaterialDataMap);
{
"DISPLACEMENT");
"DISPLACEMENT");
"DISPLACEMENT");
"DAMPER", "MESH_NODE_POSITIONS");
}
std::map<int, KelvinVoigtDamper::BlockMaterialData>::iterator
bit =
damper.blockMaterialDataMap.begin();
for (;
bit != damper.blockMaterialDataMap.end();
bit++) {
bit->second.lInear = linear;
damper.constitutiveEquationMap.insert(
material_data));
MBTET, "DAMPER");
}
CHKERR damper.setOperators(3);
}
elastic.getLoopFeEnergy(),
inertia.getLoopFeEnergy());
"DOT_DISPLACEMENT");
"DOT_VELOCITY");
if (!check_if_spatial_field_exist) {
"MESH_NODE_POSITIONS");
}
{
"FLUID_PRESSURE_FE");
if (is_partitioned) {
pcomm->size());
} else {
}
}
"FLUID_PRESSURE_FE");
"MASS_ELEMENT");
"VELOCITY_ELEMENT");
if (is_partitioned) {
pcomm->size());
} else {
}
TS ts;
CHKERR TSCreate(PETSC_COMM_WORLD, &ts);
CHKERR TSSetType(ts, TSBEULER);
->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>("Kuu",
CHKERR MatDuplicate(shellAij_ctx->
K, MAT_DO_NOT_COPY_VALUES,
D,
"DYNAMICS",
COL, shellAij_ctx->
u,
"Kuu",
COL,
D,
"DYNAMICS",
"VELOCITY",
COL, shellAij_ctx->
v,
"Kuu",
"DISPLACEMENT",
Mat shell_Aij;
problem_ptr->
getNbDofsRow(), (
void *)shellAij_ctx, &shell_Aij);
CHKERR MatShellSetOperation(shell_Aij, MATOP_MULT,
shell_Aij, MATOP_ZERO_ENTRIES,
ConvectiveMassElement::ShellMatrixElement shell_matrix_element(m_field);
m_field,
"DISPLACEMENT", shellAij_ctx->
barK, PETSC_NULL, PETSC_NULL);
shell_matrix_element.problemName = "Kuu";
shell_matrix_element.shellMatCtx = shellAij_ctx;
shell_matrix_element.DirichletBcPtr = &shell_dirichlet_bc;
shell_matrix_element.loopK.push_back(
ConvectiveMassElement::ShellMatrixElement::PairNameFEMethodPtr(
"ELASTIC", &elastic.getLoopFeLhs()));
shell_matrix_element.loopK.push_back(
ConvectiveMassElement::ShellMatrixElement::PairNameFEMethodPtr(
"ELASTIC", &damper.feLhs));
CHKERR inertia.setShellMatrixMassOperators(
"VELOCITY",
"DISPLACEMENT",
"MESH_NODE_POSITIONS", linear);
shell_matrix_element.loopM.push_back(
ConvectiveMassElement::ShellMatrixElement::PairNameFEMethodPtr(
"ELASTIC", &inertia.getLoopFeMassLhs()));
shell_matrix_element.loopAuxM.push_back(
ConvectiveMassElement::ShellMatrixElement::PairNameFEMethodPtr(
"ELASTIC", &inertia.getLoopFeMassAuxLhs()));
shell_matrix_residual.shellMatCtx = shellAij_ctx;
boost::ptr_map<std::string, NeumannForcesSurface> surface_forces;
{
string fe_name_str = "FORCE_FE";
surface_forces.at(fe_name_str).getLoopFe(), false,
false);
CHKERR surface_forces.at(fe_name_str)
.addForce("DISPLACEMENT", PETSC_NULL, it->getMeshsetId(), true);
surface_forces.at(fe_name_str)
}
}
boost::ptr_map<std::string, NeumannForcesSurface> surface_pressure;
{
string fe_name_str = "PRESSURE_FE";
surface_pressure.at(fe_name_str).getLoopFe(), false,
false);
CHKERR surface_pressure.at(fe_name_str)
.addPressure("DISPLACEMENT", PETSC_NULL, it->getMeshsetId(), true);
surface_pressure.at(fe_name_str)
}
}
boost::ptr_map<std::string, EdgeForce> edge_forces;
{
string fe_name_str = "FORCE_FE";
edge_forces.insert(fe_name_str,
new EdgeForce(m_field));
CHKERR edge_forces.at(fe_name_str)
.addForce("DISPLACEMENT", PETSC_NULL, it->getMeshsetId(), true);
edge_forces.at(fe_name_str).methodsOp.push_back(
new TimeForceScale());
}
}
boost::ptr_map<std::string, NodalForce> nodal_forces;
{
string fe_name_str = "FORCE_FE";
nodal_forces.insert(fe_name_str,
new NodalForce(m_field));
CHKERR nodal_forces.at(fe_name_str)
.addForce(
"DISPLACEMENT",
F, it->getMeshsetId(),
true);
nodal_forces.at(fe_name_str).methodsOp.push_back(
new TimeForceScale());
}
}
m_field, ts, "VELOCITY", "DISPLACEMENT");
auto add_static_rhs = [&](auto &loops_to_do_Rhs) {
loops_to_do_Rhs.push_back(
for (auto fit = surface_forces.begin(); fit != surface_forces.end();
fit++) {
loops_to_do_Rhs.push_back(
}
for (auto fit = surface_pressure.begin(); fit != surface_pressure.end();
fit++) {
loops_to_do_Rhs.push_back(
}
for (auto fit = edge_forces.begin(); fit != edge_forces.end(); fit++) {
loops_to_do_Rhs.push_back(
}
for (auto fit = nodal_forces.begin(); fit != nodal_forces.end(); fit++) {
loops_to_do_Rhs.push_back(
}
"FLUID_PRESSURE_FE", &fluid_pressure_fe.getLoopFe()));
};
CHKERR add_static_rhs(loops_to_do_Rhs);
loops_to_do_Rhs.push_back(
loopsMonitor.push_back(
loopsMonitor.push_back(
double ftime = 1;
CHKERR TSSetDuration(ts, PETSC_DEFAULT, ftime);
SNES snes;
KSP ksp;
CHKERR SNESGetKSP(snes, &ksp);
CHKERR KSPSetFromOptions(ksp);
PC pc;
CHKERR PCSetType(pc, PCSHELL);
CHKERR PCShellSetContext(pc, (
void *)&pc_shell_ctx);
CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
"DYNAMICS",
COL,
D, INSERT_VALUES, SCATTER_REVERSE);
if (is_solve_at_time_zero) {
Mat Aij = shellAij_ctx->
K;
"Kuu",
COL,
D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
SNES snes;
CHKERR SNESCreate(PETSC_COMM_WORLD, &snes);
CHKERR SNESSetApplicationContext(snes, &snes_ctx);
CHKERR SNESSetFromOptions(snes);
snes_ctx.getComputeRhs();
snes_ctx.getPreProcComputeRhs().push_back(&my_dirichlet_bc);
fluid_pressure_fe.getLoopFe().ts_t = 0;
CHKERR add_static_rhs(loops_to_do_Rhs);
snes_ctx.getPostProcComputeRhs().push_back(&my_dirichlet_bc);
snes_ctx.getSetOperators();
snes_ctx.getPreProcSetOperators().push_back(&my_dirichlet_bc);
loops_to_do_Mat.push_back(
snes_ctx.getPostProcSetOperators().push_back(&my_dirichlet_bc);
"DOT_DISPLACEMENT");
"Kuu",
COL,
D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR SNESSolve(snes, PETSC_NULL,
D);
int its;
CHKERR SNESGetIterationNumber(snes, &its);
MOFEM_LOG_C(
"DYNAMIC", Sev::inform,
"number of Newton iterations = %d\n",
its);
"Kuu",
COL,
D, INSERT_VALUES, SCATTER_REVERSE);
}
if (is_solve_at_time_zero) {
"DYNAMICS",
COL,
D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
}
#if PETSC_VERSION_GE(3, 7, 0)
CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_STEPOVER);
#endif
PetscInt steps, snesfails, rejects, nonlinits, linits;
CHKERR TSGetTimeStepNumber(ts, &steps);
CHKERR TSGetSNESFailures(ts, &snesfails);
CHKERR TSGetStepRejections(ts, &rejects);
CHKERR TSGetSNESIterations(ts, &nonlinits);
CHKERR TSGetKSPIterations(ts, &linits);
"steps %d (%d rejected, %D SNES fails), ftime %g, nonlinits "
"%d, linits %D\n",
steps, rejects, snesfails, ftime, nonlinits, linits);
CHKERR MatDestroy(&shellAij_ctx->
K);
CHKERR MatDestroy(&shellAij_ctx->
M);
CHKERR MatDestroy(&shell_Aij);
delete shellAij_ctx;
}
return 0;
}