two_d_unsteady_heat_2adapt_load_balance.cc File Reference

Classes

class  MyEllipse
 
class  RefineableUnsteadyHeatProblem< ELEMENT >
 Unsteady heat problem in deformable ellipse domain. More...
 

Namespaces

 GlobalParameters
 Global parameters.
 

Functions

double GlobalParameters::step_position (const double &time)
 Position of step (x-axis intercept) More...
 
void GlobalParameters::get_exact_u (const double &time, const Vector< double > &x, Vector< double > &u)
 Exact solution as a Vector. More...
 
void GlobalParameters::get_exact_u (const double &time, const Vector< double > &x, double &u)
 Exact solution as a scalar. More...
 
void GlobalParameters::get_source (const double &time, const Vector< double > &x, double &source)
 Source function. More...
 
void GlobalParameters::prescribed_flux_on_fixed_y_boundary (const double &time, const Vector< double > &x, double &flux)
 Flux required by the exact solution on a boundary on which y is fixed. More...
 
int main (int argc, char *argv[])
 

Variables

std::string GlobalParameters::Restart_file =""
 Name of restart file. More...
 
std::string GlobalParameters::Partitioning_file =""
 Name of file specifying the partitioning of the problem. More...
 
double GlobalParameters::Alpha =1.0
 Parameter for steepness of step. More...
 
double GlobalParameters::Beta =1.0
 Parameter for amplitude of step translation. More...
 
double GlobalParameters::Gamma = MathematicalConstants::Pi/4.0
 Parameter for timescale of step translation. More...
 
double GlobalParameters::TanPhi =0.0
 Parameter for angle of step. More...
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// Demonstrate how to solve an unsteady heat problem in deformable domain with mesh adaptation.

1237 {
1238 
1239 #ifdef OOMPH_HAS_MPI
1240  MPI_Helpers::init(argc,argv);
1241 #endif
1242 
1243  // Store command line arguments
1244  CommandLineArgs::setup(argc,argv);
1245 
1246  // Define possible command line arguments and parse the ones that
1247  // were actually specified
1248 
1249  // Name of restart file
1252 
1253  // Name of file that specifies the problem partitioning
1255  "--partitioning_file",&GlobalParameters::Partitioning_file);
1256 
1257  // Flag to indicate that we're doing a validation run
1258  CommandLineArgs::specify_command_line_flag("--validation_run");
1259 
1260  // Flag to indicate that we do load_balance first (before prune)
1261  CommandLineArgs::specify_command_line_flag("--load_balance_first");
1262 
1263  // Parse command line
1265 
1266  // Doc what has actually been specified on the command line
1268 
1269  // Build problem: Pass pointer to source function and initial timestep
1272 
1273  // Work out doc_info directory
1274  char doc_info_directory[100];
1275  if(CommandLineArgs::command_line_flag_has_been_set("--validation_run"))
1276  {
1277  //Validation run
1278  if(CommandLineArgs::command_line_flag_has_been_set("--load_balance_first"))
1279  {
1280  //Load balancing
1282  {
1283  //First run
1284  sprintf(doc_info_directory,"RESLT_load_balance_first_for_restart");
1285  }
1286  else
1287  {
1288  //Restarting
1289  //cout << GlobalParameters::Restart_file.c_str() << endl;
1290  char filename[100];
1291  sprintf(filename,"%s",GlobalParameters::Restart_file.c_str());
1292  char* step;
1293  step = strtok(filename,"/");
1294  step = strtok(NULL,"/");
1295  sprintf(doc_info_directory,"RESLT_load_balance_first_restarted_from_step_%s",step);
1296  //cout << doc_info_directory << endl;
1297  //exit(1);
1298  }
1299  }
1300  else
1301  {
1302  //Pruning
1304  {
1305  //First run
1306  sprintf(doc_info_directory,"RESLT_prune_first_for_restart");
1307  }
1308  else
1309  {
1310  //Restarting
1311  char filename[100];
1312  sprintf(filename,"%s",GlobalParameters::Restart_file.c_str());
1313  char* step;
1314  step = strtok(filename,"/");
1315  step = strtok(NULL,"/");
1316  sprintf(doc_info_directory,"RESLT_prune_first_restarted_from_step_%s",step);
1317  }
1318  }
1319  }
1320  else
1321  {
1322  sprintf(doc_info_directory,"RESLT");
1323  }
1324 
1325  // Set doc_info directory
1326  problem.doc_info().set_directory(doc_info_directory);
1327 
1328  // Switch off output modifier
1330 
1331  // Define processor-labeled output file for all on-screen stuff
1332  std::ofstream output_stream;
1333  char filename[100];
1334  sprintf(filename,"%s/OUTPUT.%i",
1335  problem.doc_info().directory().c_str(),
1336  MPI_Helpers::communicator_pt()->my_rank());
1337  output_stream.open(filename);
1338  oomph_info.stream_pt() = &output_stream;
1339  OomphLibWarning::set_stream_pt(&output_stream);
1340  OomphLibError::set_stream_pt(&output_stream);
1341 
1342  // Doc what has actually been specified on the command line
1344 
1345  // First timestep?
1346  bool first=true;
1347 
1348  // Max. number of spatial adaptations per timestep. Allow plenty
1349  // of adaptations at first timestep as the initial conditions
1350  // can be reset "exactly" from without any interpolation error.
1351  unsigned max_adapt=10;
1352 
1353  // Set IC from analytical soln
1354  problem.set_initial_condition();
1355 
1356  // If restart: The first step isn't really the first step,
1357  // i.e. initial condition should not be re-set when
1358  // adaptive refinement has been performed. Also, limit
1359  // the max. number of refinements per timestep to the
1360  // normal value straightaway.
1362  {
1363  first=false;
1364  max_adapt=1;
1365  }
1366 
1367 
1368  // Prune first or load balance first?
1369  unsigned first_load_balance=9;
1370  unsigned second_load_balance=18;
1371  unsigned first_prune=4;
1372  unsigned second_prune=13;
1373 
1374  // Create storage for partitioning
1375  Vector<unsigned> element_partition;
1376 
1377  // No partitioning specified -- simply distribute problem and
1378  // record distribution in file to allow restart
1379  if (!CommandLineArgs::command_line_flag_has_been_set("--partitioning_file"))
1380  {
1381  oomph_info << "Distributing problem with METIS \n"
1382  << "Documenting partitioning in RESLT/partitioning.dat.\n";
1383 
1384  // Distribute
1385  element_partition=problem.distribute();
1386 
1387  // Write partition to disk
1388  std::ofstream output_file;
1389  char filename[100];
1390  sprintf(filename,"%s/partitioning.dat",problem.doc_info().directory().c_str());
1391  output_file.open(filename);
1392  unsigned n=element_partition.size();
1393  output_file << element_partition.size() << std::endl;
1394  for (unsigned e=0;e<n;e++)
1395  {
1396  output_file << element_partition[e] << std::endl;
1397  }
1398  output_file.close();
1399  }
1400  // Read in partitioning from disk using the specified file
1401  else
1402  {
1403 
1404  oomph_info << "Distributing problem with partitioning \n"
1405  << "specified in: " << GlobalParameters::Partitioning_file
1406  << std::endl;
1407 
1408  // Read in partitioning from disk: Name of partitioning file specified
1409  // as command line argument
1410  std::ifstream input_file;
1411  input_file.open(GlobalParameters::Partitioning_file.c_str());
1412  if (!input_file.is_open())
1413  {
1414  oomph_info << "Error opening input file\n";
1415  assert(false);
1416  }
1417  std::string input_string;
1418  unsigned n=0;
1419  if (getline(input_file,input_string,'\n'))
1420  {
1421  n=atoi(input_string.c_str());
1422  }
1423  else
1424  {
1425  oomph_info << "Reached end of file when reading partitioning file\n";
1426  assert(false);
1427  }
1428  element_partition.resize(n);
1429  for (unsigned e=0;e<n;e++)
1430  {
1431  if (getline(input_file,input_string,'\n'))
1432  {
1433  element_partition[e]=atoi(input_string.c_str());
1434  }
1435  else
1436  {
1437  oomph_info << "Reached end of file when reading partitioning file\n";
1438  assert(false);
1439  }
1440  }
1441 
1442  // Create storage for actually used partitioning
1443  Vector<unsigned> used_element_partition;
1444 
1445  // Now perform the distribution
1446  used_element_partition=problem.distribute(element_partition);
1447 
1448 
1449  // Write used partition to disk
1450  std::ofstream output_file;
1451  char filename[100];
1452  sprintf(filename,"%s/partitioning.dat",problem.doc_info().directory().c_str());
1453  output_file.open(filename);
1454  unsigned n_used=used_element_partition.size();
1455  output_file << n_used << std::endl;
1456  for (unsigned e=0;e<n_used;e++)
1457  {
1458  output_file << used_element_partition[e] << std::endl;
1459  }
1460  output_file.close();
1461 
1462  }
1463 
1464 
1465  // Doc
1466  std::stringstream comment_stream0;
1467  comment_stream0 << "Distributed; Step "
1468  << problem.doc_info().number();
1469  problem.doc_solution(comment_stream0.str());
1470  oomph_info << "Finished distribution\n";
1471 
1472 // Restart file specified via command line
1474  {
1475  problem.restart();
1476  oomph_info << "Finished restart\n";
1477  }
1478 
1479  // Initial timestep: Use the one used when setting up the initial
1480  // condition or the "suggested next dt" from the restarted run
1481  double dt=problem.next_dt();
1482 
1483  // Write header for trace file
1484  problem.write_trace_file_header();
1485 
1486  // Timestepping loop
1487  if (CommandLineArgs::command_line_flag_has_been_set("--validation_run"))
1488  {
1489  // Fake but repeatable load balancing for self-test
1490  problem.set_default_partition_in_load_balance();
1491  }
1492 
1493 
1494  // Keep solving...
1495  while (problem.doc_info().number()<22)
1496  {
1497 
1498  oomph_info << "Doing solve\n";
1499 
1500  // Take timestep with temporal and spatial adaptivity
1501  double dt_new=
1502  problem.doubly_adaptive_unsteady_newton_solve(dt,problem.epsilon_t(),
1503  max_adapt,first);
1504  oomph_info << "Suggested new dt: " << dt_new << std::endl;
1505  dt=dt_new;
1506 
1507  // Store for restart
1508  problem.next_dt()=dt;
1509 
1510  // Now we've done the first timestep -- don't re-set the IC
1511  // in subsequent steps
1512  first=false;
1513 
1514  // Reduce the number of spatial adaptations to one per
1515  // timestep -- too scared that the interpolation error will
1516  // wipe out any further gains...
1517  max_adapt=1;
1518 
1519  //Output solution
1520  std::stringstream comment_stream;
1521  comment_stream << "Step " << problem.doc_info().number();
1522  problem.doc_solution(comment_stream.str());
1523 
1524  // Prune
1525  if ((problem.doc_info().number()==first_prune)||
1526  (problem.doc_info().number()==second_prune))
1527  {
1528  std::stringstream comment_stream1;
1529  if ((problem.doc_info().number()==second_prune)||
1530  ((problem.doc_info().number()==first_prune)&&
1532  "--load_balance_first"))))
1533  {
1534  oomph_info << "Refining uniformly before pruning\n";
1535  problem.refine_uniformly();
1536  comment_stream1 << "Uniform refinement; Step "
1537  << problem.doc_info().number();
1538  }
1539  else
1540  {
1541  comment_stream1 << "Skipped uniform refinement; Step "
1542  << problem.doc_info().number();
1543  }
1544  problem.doc_solution(comment_stream1.str());
1545 
1546  std::stringstream comment_stream2;
1547  if ((problem.doc_info().number()==second_prune+1)||
1548  ((problem.doc_info().number()==first_prune+1)&&
1550  "--load_balance_first"))))
1551  {
1552  oomph_info << "Pruning\n";
1553  problem.prune_halo_elements_and_nodes();
1554  comment_stream2 << "Pruned; Step "
1555  << problem.doc_info().number();
1556  }
1557  else
1558  {
1559  comment_stream2 << "Skipped prune; Step "
1560  << problem.doc_info().number();
1561  }
1562  problem.doc_solution(comment_stream2.str());
1563  }
1564 
1565 
1566 
1567  // Load balance?
1568  if ((problem.doc_info().number()==first_load_balance)||
1569  (problem.doc_info().number()==second_load_balance))
1570  {
1571  oomph_info << "\n\n\n LOAD BALANCING \n\n\n";
1572 
1573  // Load balance
1574  problem.load_balance();
1575 
1576  std::stringstream comment_stream3;
1577  comment_stream3 << "Load balanced; Step "
1578  << problem.doc_info().number();
1579  problem.doc_solution(comment_stream3.str());
1580 
1581 
1582  oomph_info << "\n\n\n DONE LOAD BALANCING \n\n\n";
1583  }
1584  }
1585 
1586  oomph_info << "Done\n";
1587 #ifdef OOMPH_HAS_MPI
1588  MPI_Helpers::finalize();
1589 #endif
1590 
1591 }; // end of main
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define assert(e,...)
Definition: Logger.h:744
Unsteady heat problem in deformable ellipse domain.
Definition: two_d_unsteady_heat_2adapt_load_balance.cc:223
std::ostream *& stream_pt()
Access function for the stream pointer.
Definition: oomph_definitions.h:464
OutputModifier *& output_modifier_pt()
Access function for the output modifier pointer.
Definition: oomph_definitions.h:476
void setup(Time *time_pt)
Create all GeomObjects needed to define the cylinder and the flag.
Definition: turek_flag_non_fsi.cc:277
std::string Partitioning_file
Name of file specifying the partitioning of the problem.
Definition: two_d_unsteady_heat_2adapt_load_balance.cc:135
void get_source(const double &time, const Vector< double > &x, double &source)
Source function.
Definition: stefan_boltzmann.cc:154
std::string Restart_file
Name of restart file.
Definition: two_d_unsteady_heat_2adapt_load_balance.cc:132
string filename
Definition: MergeRestartFiles.py:39
bool command_line_flag_has_been_set(const std::string &flag)
Definition: oomph_utilities.cc:501
void specify_command_line_flag(const std::string &command_line_flag, const std::string &doc)
Specify possible argument-free command line flag.
Definition: oomph_utilities.cc:451
void parse_and_assign(int argc, char *argv[], const bool &throw_on_unrecognised_args)
Definition: oomph_utilities.cc:760
void doc_specified_flags()
Document specified command line flags.
Definition: oomph_utilities.cc:610
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
OutputModifier default_output_modifier
Single global instatiation of the default output modifier.
Definition: oomph_definitions.cc:325
OomphInfo oomph_info
Definition: oomph_definitions.cc:319
Constructor for SteadyAxisymAdvectionDiffusion problem
Definition: steady_axisym_advection_diffusion.cc:213

References assert, oomph::CommandLineArgs::command_line_flag_has_been_set(), oomph::default_output_modifier, oomph::CommandLineArgs::doc_specified_flags(), e(), MergeRestartFiles::filename, GlobalParameters::get_source(), n, oomph::oomph_info, oomph::OomphInfo::output_modifier_pt(), oomph::CommandLineArgs::parse_and_assign(), GlobalParameters::Partitioning_file, problem, GlobalParameters::Restart_file, Flag_definition::setup(), oomph::CommandLineArgs::specify_command_line_flag(), oomph::OomphInfo::stream_pt(), and oomph::Global_string_for_annotation::string().