Skip to content

Commit

Permalink
Changed gold files
Browse files Browse the repository at this point in the history
  • Loading branch information
fdkong committed Apr 18, 2019
1 parent d93c73f commit 5a59e7e
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MultiAppFieldTransferInterface : public MultiAppTransfer
std::vector<PostprocessorName> _to_postprocessor_to_be_preserved;

private:
void adjustTransferedSolution(FEProblemBase & from_problem,
void adjustTransferedSolution(FEProblemBase * from_problem,
PostprocessorName & from_postprocessor,
FEProblemBase & to_problem,
PostprocessorName & to_postprocessor);
Expand Down
2 changes: 1 addition & 1 deletion framework/include/transfers/MultiAppMeshFunctionTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef MULTIAPPMESHFUNCTIONTRANSFER_H
#define MULTIAPPMESHFUNCTIONTRANSFER_H

#include "MultiAppTransfer.h"
#include "MultiAppFieldTransferInterface.h"

// Forward declarations
class MultiAppMeshFunctionTransfer;
Expand Down
120 changes: 102 additions & 18 deletions framework/src/transfers/MultiAppFieldTransferInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "FEProblem.h"
#include "MultiApp.h"
#include "MooseMesh.h"
#include "UserObject.h"

template <>
InputParameters
Expand Down Expand Up @@ -84,7 +85,7 @@ MultiAppFieldTransferInterface::postExecute()
FEProblemBase & from_problem = _multi_app->problemBase();
for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
if (_multi_app->hasLocalApp(i))
adjustTransferedSolution(from_problem,
adjustTransferedSolution(&from_problem,
_from_postprocessor_to_be_preserved[i],
_multi_app->appProblemBase(i),
_to_postprocessor_to_be_preserved[0]);
Expand All @@ -94,42 +95,125 @@ MultiAppFieldTransferInterface::postExecute()
{
FEProblemBase & to_problem = _multi_app->problemBase();
for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
if (_multi_app->hasLocalApp(i))
adjustTransferedSolution(_multi_app->appProblemBase(i),
_from_postprocessor_to_be_preserved[0],
to_problem,
_to_postprocessor_to_be_preserved[i]);
{
adjustTransferedSolution(_multi_app->hasLocalApp(i) ? &_multi_app->appProblemBase(i)
: nullptr,
_from_postprocessor_to_be_preserved[0],
to_problem,
_to_postprocessor_to_be_preserved[i]);
}
}

_console << "Finished Conservative transfers " << name() << std::endl;
}
}

void
MultiAppFieldTransferInterface::adjustTransferedSolution(FEProblemBase & from_problem,
MultiAppFieldTransferInterface::adjustTransferedSolution(FEProblemBase * from_problem,
PostprocessorName & from_postprocessor,
FEProblemBase & to_problem,
PostprocessorName & to_postprocessor)
{
PostprocessorValue & from_adjuster = from_problem.getPostprocessorValue(from_postprocessor);
PostprocessorValue from_adjuster = 0;
if (from_problem)
{
from_adjuster = from_problem->getPostprocessorValue(from_postprocessor);
}
else
{
from_adjuster = 0;
}
/* Everyone on master side should know this value, and use it to scale the solution */
if (_direction == FROM_MULTIAPP)
{
comm().max(from_adjuster);
}

// Compute to-postproessor to have the adjuster
to_problem.computeUserObjectByName(EXEC_TRANSFER, to_postprocessor);

std::cout << "from_postprocessor " << from_postprocessor << std::endl;
std::cout << "to_postprocessor " << to_postprocessor << std::endl;

// Now we should have the right adjuster based on the transfered solution
PostprocessorValue & to_adjuster = to_problem.getPostprocessorValue(to_postprocessor);

auto & to_var = to_problem.getVariable(
0, _to_var_name[0], Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
auto & to_sys = to_var.sys().system();
auto var_num = to_sys.variable_number(_to_var_name[0]);
auto sys_num = to_sys.number();
auto * pps =
dynamic_cast<const BlockRestrictable *>(&(to_problem.getUserObjectBase(to_postprocessor)));
auto & to_solution = to_var.sys().solution();
auto & to_mesh = to_problem.mesh().getMesh();
auto & moose_mesh = to_problem.mesh();
bool is_nodal = to_sys.variable_type(var_num).family == LAGRANGE;
if (is_nodal)
{
for (const auto & node : to_mesh.local_node_ptr_range())
{
// Skip this node if the variable has no dofs at it.
if (node->n_dofs(sys_num, var_num) < 1)
continue;

std::cout << "from_adjuster " << from_adjuster << std::endl;
std::cout << "to_adjuster " << to_adjuster << std::endl;
bool scale_current_node = false;
/* If we care about block IDs */
if (pps)
{
auto & blockids = pps->blockIDs();
auto & node_to_elem_map = moose_mesh.nodeToElemMap();
auto neighbor_elements = node_to_elem_map.find(node->id());
for (auto element : neighbor_elements->second)
{
auto & elem = to_mesh.elem_ref(element);
if (blockids.find(elem.subdomain_id()) != blockids.end() ||
blockids.find(Moose::ANY_BLOCK_ID) != blockids.end())
{
scale_current_node = true;
break;
}
}
}
else
{
scale_current_node = true;
}
/* Need to scale this node */
if (scale_current_node)
{
dof_id_type dof = node->dof_number(sys_num, var_num, 0);
to_solution.set(dof, (from_adjuster / to_adjuster) * to_solution(dof));
}
}
}
else
{
for (auto & elem : as_range(to_mesh.local_elements_begin(), to_mesh.local_elements_end()))
{
// Skip this element if the variable has no dofs at it.
if (elem->n_dofs(sys_num, var_num) < 1)
continue;

bool scale_current_element = false;
if (pps)
{
auto & blockids = pps->blockIDs();
if (blockids.find(elem->subdomain_id()) != blockids.end() ||
blockids.find(Moose::ANY_BLOCK_ID) != blockids.end())
{
scale_current_element = true;
}
}
else
{
scale_current_element = true;
}
if (scale_current_element)
{
dof_id_type dof = elem->dof_number(sys_num, var_num, 0);
to_solution.set(dof, (from_adjuster / to_adjuster) * to_solution(dof));
}
}
}

// Scale the solution.
// to_var.sys().solution().scale(from_adjuster / to_adjuster);
to_var.sys().solution().scale(from_adjuster / to_adjuster);
// Update the local solution
to_var.sys().update();
to_solution.close();
to_sys.update();
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions test/tests/transfers/multiapp_conservative_transfer/tests
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
input = master_power_density.i
exodiff = 'master_power_density_out.e master_power_density_out_sub0.e master_power_density_out_sub1.e'
requirement = 'MOOSE shall support conservative transfers'
min_parallel = 2
[../]
[]

0 comments on commit 5a59e7e

Please sign in to comment.