Skip to content
Permalink
Browse files

Merge pull request #13112 from permcody/scalar_ic_file

Support setting Scalar IC from file
  • Loading branch information...
lindsayad committed Mar 26, 2019
2 parents 4cd79ec + ddaee6e commit 834a2fefad2a693dbd9a5d9fb63823e30b8a0364
@@ -935,10 +935,36 @@ SystemBase::copyVars(ExodusII_IO & io)
}

did_copy = true;
if (getVariable(0, vci._dest_name).isNodal())
io.copy_nodal_solution(system(), vci._dest_name, vci._source_name, timestep);
else
io.copy_elemental_solution(system(), vci._dest_name, vci._source_name, timestep);

if (hasVariable(vci._dest_name))
{
if (getVariable(0, vci._dest_name).isNodal())
io.copy_nodal_solution(system(), vci._dest_name, vci._source_name, timestep);
else
io.copy_elemental_solution(system(), vci._dest_name, vci._source_name, timestep);
}
else if (hasScalarVariable(vci._dest_name))
{
auto rank = comm().rank();
auto size = comm().size();

// Read solution on rank 0 only and send data to rank "size - 1" where scalar DOFs are stored
std::vector<Real> global_values;
if (rank == 0)
{
// Read the scalar value then set that value in the current solution
io.read_global_variable({vci._source_name}, timestep, global_values);
if (size > 1)
comm().send(size - 1, global_values);
}
if (rank == size - 1)
{
if (size > 1)
comm().receive(0, global_values);
const unsigned int var_num = system().variable_number(vci._dest_name);
system().solution->set(var_num, global_values[0]);
}
}
}

if (did_copy)
@@ -0,0 +1,88 @@
[Mesh]
type = FileMesh
file = 'coupled_ode_td_out.e'
[]

[Variables]
[./f]
family = SCALAR
order = FIRST
initial_condition = 1
[../]
[./f_times_mult]
family = SCALAR
order = FIRST
initial_condition = 1
[../]
[]

[ScalarKernels]
[./dT]
type = CoupledODETimeDerivative
variable = f
v = f_times_mult
[../]

[./src]
type = ParsedODEKernel
variable = f
function = '-1'
[../]

[./f_times_mult_1]
type = ParsedODEKernel
variable = f_times_mult
function = 'f_times_mult'
[../]

[./f_times_mult_2]
type = ParsedODEKernel
variable = f_times_mult
function = '-f * g'
args = 'f g'
[../]
[]

[AuxVariables]
[./g]
family = SCALAR
order = FIRST
initial_from_file_var = g
initial_from_file_timestep = 'LATEST'
[../]
[]

[Functions]
[./function_g]
type = ParsedFunction
value = '(1 + t)'
[../]
[]

[AuxScalarKernels]
[./set_g]
type = FunctionScalarAux
function = function_g
variable = g
execute_on = 'timestep_end'
[../]
[]

[Postprocessors]
[./f]
type = ScalarVariable
variable = f
execute_on = 'initial timestep_end'
[../]
[]

[Executioner]
type = Transient
dt = 1
num_steps = 3
nl_abs_tol = 1e-9
[]

[Outputs]
csv = true
[]
@@ -0,0 +1,88 @@
[Mesh]
type = FileMesh
file = 'coupled_ode_td_out.e'
[]

[Variables]
[./f]
family = SCALAR
order = FIRST
initial_from_file_var = f
initial_from_file_timestep = 'LATEST'
[../]
[./f_times_mult]
family = SCALAR
order = FIRST
initial_from_file_var = f_times_mult
initial_from_file_timestep = 'LATEST'
[../]
[]

[ScalarKernels]
[./dT]
type = CoupledODETimeDerivative
variable = f
v = f_times_mult
[../]

[./src]
type = ParsedODEKernel
variable = f
function = '-1'
[../]

[./f_times_mult_1]
type = ParsedODEKernel
variable = f_times_mult
function = 'f_times_mult'
[../]

[./f_times_mult_2]
type = ParsedODEKernel
variable = f_times_mult
function = '-f * g'
args = 'f g'
[../]
[]

[AuxVariables]
[./g]
family = SCALAR
order = FIRST
[../]
[]

[Functions]
[./function_g]
type = ParsedFunction
value = '(1 + t)'
[../]
[]

[AuxScalarKernels]
[./set_g]
type = FunctionScalarAux
function = function_g
variable = g
execute_on = 'linear initial'
[../]
[]

[Postprocessors]
[./f]
type = ScalarVariable
variable = f
execute_on = 'initial timestep_end'
[../]
[]

[Executioner]
type = Transient
dt = 1
num_steps = 3
nl_abs_tol = 1e-9
[]

[Outputs]
csv = true
[]
@@ -0,0 +1,5 @@
time,f,f_times_mult,g
0,1,1,4
1,0.50000000017468,1.9999999958597,2
2,1.5000000001934,2.9999999905691,3
3,1.3333333360971,3.9999999955478,4
@@ -0,0 +1,5 @@
time,f,f_times_mult,g
0,0.99999999941097,3.9999999925368,1
1,2.4999999898938,4.9999999988618,2
2,2.0000000000937,5.999999997199,3
3,1.7499999990439,7.0000000029099,4
@@ -3,14 +3,22 @@
type = 'Exodiff'
input = 'ode_expl_test.i'
exodiff = 'ode_expl_test_out.e'

design = ""
issues = "#726"
requirement = "The system shall support solving Ordinary Differential Equations in explicit form."
[../]

[./test_sys_impl]
type = 'Exodiff'
input = 'ode_sys_impl_test.i'
exodiff = 'ode_sys_impl_test_out.e'
max_parallel = 2
max_threads = 2
max_threads = 2

design = ""
issues = "#726"
requirement = "The system shall support solving Ordinary Differential Equations in implicit form."
[../]

[./test_parsed_sys_impl]
@@ -21,11 +29,42 @@
exodiff = 'ode_sys_impl_test_out.e'
max_parallel = 2
max_threads = 2

design = ""
issues = "#726"
requirement = "The system shall support solving ODEs specified within the input file through parsed function syntax."
[../]

[./test_coupled_ode_td]
type = 'CSVDiff'
input = 'coupled_ode_td.i'
csvdiff = 'coupled_ode_td_out.csv'
cli_args = 'Outputs/exodus=true' # Turn on Exodus for the Scalar IC tests

design = ""
issues = "#726"
requirement = "The system shall support solving Coupled Ordinary Differential Equations."
[../]

[./test_coupled_ode_td_var_ic_from_mesh]
type = 'CSVDiff'
input = 'coupled_ode_td_var_ic_from_mesh.i'
csvdiff = 'coupled_ode_td_var_ic_from_mesh_out.csv'
prereq = 'test_coupled_ode_td'

design = ""
issues = "#13040"
requirement = "The system shall allow scalar variable initial condition to be loaded from a file mesh"
[../]

[./test_coupled_ode_td_auxvar_ic_from_mesh]
type = 'CSVDiff'
input = 'coupled_ode_td_auxvar_ic_from_mesh.i'
csvdiff = 'coupled_ode_td_auxvar_ic_from_mesh_out.csv'
prereq = 'test_coupled_ode_td'

design = ""
issues = "#13040"
requirement = "The system shall allow auxscalar variable initial condition to be loaded from a file mesh"
[../]
[]

0 comments on commit 834a2fe

Please sign in to comment.
You can’t perform that action at this time.