Permalink
Browse files

Merge pull request #12740 from aeslaughter/transfer-final-9923

Add the ability to execute transfers on final
  • Loading branch information...
permcody committed Jan 24, 2019
2 parents a8d9295 + 9138b3d commit 76da88f077180c8ff2f32b91fd8e68c6e1df202b
@@ -88,11 +88,15 @@ std::vector<std::string> split(const std::string & str, const std::string & deli

/**
* Python like join function for strings.
*/
template <typename T>
std::string join(const T & strings, const std::string & delimiter);

/**
* Check the file size.
*/
std::size_t fileSize(const std::string & filename);

/**
* This function tokenizes a path and checks to see if it contains the string to look for
*/
@@ -146,7 +146,7 @@ class MultiMooseEnum : public MooseEnumBase
void clear();

/**
* Return the number of items in the MultiMooseEnum
* Return the number of active items in the MultiMooseEnum
*/
unsigned int size() const;

@@ -225,7 +225,7 @@ Transient::Transient(const InputParameters & parameters)
_relaxed_vars(getParam<std::vector<std::string>>("relaxed_variables")),
_final_timer(registerTimedSection("final", 1))
{
// Handl deprecated parameters
// Handle deprecated parameters
if (!parameters.isParamSetByAddParam("trans_ss_check"))
_steady_state_detection = getParam<bool>("trans_ss_check");

@@ -395,10 +395,10 @@ Transient::execute()
if (!_app.halfTransient())
{
TIME_SECTION(_final_timer);

_problem.execMultiApps(EXEC_FINAL);
_problem.finalizeMultiApps();
_problem.outputStep(EXEC_FINAL);
_problem.execute(EXEC_FINAL);
_problem.outputStep(EXEC_FINAL);
}

// This method is to finalize anything else we want to do on the problem side.
@@ -363,10 +363,6 @@ Exodus::outputInput()
void
Exodus::output(const ExecFlagType & type)
{
// Do nothing if there is nothing to output
if (!hasOutput(type))
return;

// Prepare the ExodusII_IO object
outputSetup();
LockFile lf(filename(), processor_id() == 0);
@@ -399,6 +395,23 @@ Exodus::output(const ExecFlagType & type)

// Reset the mesh changed flag
_exodus_mesh_changed = false;

// Remove empty files
// Because of the ability to control when different items output independently (i.e.,
// "execute_on_input") it is possible to create an empty file if the solve stops early, such as
// the case when --half-transient is used. Thus, to avoid having empty files laying around the
// following cleans them up. It is not possible to know if anything will be output to the file
// prior to attempting. A long story short, an exodus file with only info records doesn't write
// correctly. Deleting the file here actually doesn't fix this problem, but it seems like poor
// form to leave empty files around.
std::string current = filename();
if (processor_id() == 0 && MooseUtils::checkFileReadable(current) &&
(MooseUtils::fileSize(current) == 0))
{
int err = std::remove(current.c_str());
if (err != 0)
mooseError("MOOSE failed to remove the empty file ", current);
}
}

std::string
@@ -830,6 +830,16 @@ clearSymlink(const std::string & link)
mooseError("Failed to remove symbolic link (via 'unlink') to ", link);
}
}

std::size_t
fileSize(const std::string & filename)
{
struct stat buffer;
if (stat(filename.c_str(), &buffer))
return 0;

return buffer.st_size;
}
} // MooseUtils namespace

std::string
@@ -0,0 +1,42 @@
[Mesh]
type = GeneratedMesh
dim = 1
[]

[Problem]
solve = false
[]

[Executioner]
type = Transient
dt = 1
num_steps = 4
[]

[Functions]
[func]
type = ConstantFunction
value = 5
[]
[]

[Postprocessors]
[timestep_end]
type = FunctionValuePostprocessor
function = 't'
execute_on = 'initial timestep_end'
[]
[final]
type = FunctionValuePostprocessor
function = '2*t'
execute_on = 'final'
[]
[]

[Outputs]
csv = true
[on_final]
type = CSV
execute_on = final
[]
[]
@@ -0,0 +1,2 @@
time,final,timestep_end
4,8,4
@@ -0,0 +1,6 @@
time,final,timestep_end
0,0,0
1,0,1
2,0,2
3,0,3
4,0,4
@@ -0,0 +1,10 @@
[Tests]
issues = '#9923'
design = 'VectorPostprocessors/index.md Outputs/index.md'
[execute_on_final]
type = CSVDiff
input = execute_on_final.i
csvdiff = 'execute_on_final_out.csv execute_on_final_on_final.csv'
requirement = "Postprocessor objects shall be able to execute and output after the simulation is complete."
[]
[]
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,66 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
[]

[Variables]
[u]
initial_condition = 1234
[]
[v]
initial_condition = 2458
[]
[]

[Problem]
type = FEProblem
solve = false
[]

[Executioner]
type = Transient
num_steps = 4
solve_type = 'PJFNK'
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[MultiApps]
[sub]
type = TransientMultiApp
input_files = sub.i
execute_on = 'INITIAL TIMESTEP_END'
[]
[]

[Transfers]
[from_sub]
type = MultiAppCopyTransfer
direction = from_multiapp
source_variable = u
variable = u
multi_app = sub
check_multiapp_execute_on = false
execute_on = 'FINAL'
[]
[to_sub]
type = MultiAppCopyTransfer
direction = to_multiapp
source_variable = v
variable = v
multi_app = sub
check_multiapp_execute_on = false
execute_on = 'FINAL'
[]
[]

[Outputs]
exodus = true
[final]
type = Exodus
execute_on = 'FINAL'
execute_input_on = 'NONE' # This is needed to avoid problems with creating a file w/o data during --recover testing
[]
[]
@@ -0,0 +1,60 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
[]

[Variables]
[u]
initial_condition = 10
[]
[]

[AuxVariables]
[v]
initial_condition = 20
[]
[]

[Kernels]
[time]
type = TimeDerivative
variable = u
[]
[diff]
type = Diffusion
variable = u
[]
[]

[BCs]
[left]
type = DirichletBC
variable = u
boundary = left
value = 10
[]
[right]
type = DirichletBC
variable = u
boundary = right
value = 20
[]
[]

[Executioner]
type = Transient
num_steps = 4
solve_type = 'PJFNK'
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
[final]
type = Exodus
execute_on = 'FINAL'
execute_input_on = 'NONE' # This is needed to avoid problems with creating a file w/o data during --recover testing
[]
[]
@@ -0,0 +1,10 @@
[Tests]
issues = '#9923'
design = 'Transfers/index.md'
[transfer_on_final]
type = Exodiff
input = master.i
exodiff = 'master_final.e master_out.e master_out_sub0.e'
requirement = "The Transfer system shall support execution with the EXEC_FINAL flag."
[]
[]

0 comments on commit 76da88f

Please sign in to comment.