Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog-entries/859.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added several simplification and fixes to the two-scale heat conduction case. Most prominently removing the data `K01` and `K10` [#859](https://github.com/precice/tutorials/pull/859)
Comment thread
MakisH marked this conversation as resolved.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 2 additions & 14 deletions two-scale-heat-conduction/macro-dumux/appl/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,14 @@ int main(int argc, char **argv)

// initialize the coupling data
std::string readDatak00;
std::string readDatak01;
std::string readDatak10;
std::string readDatak11;
std::string readDataPorosity;
std::string writeDataConcentration;

if (runWithCoupling) {
readDatak00 = couplingParticipant.getReadDataNamesOnMesh(meshName)[0];
readDatak01 = couplingParticipant.getReadDataNamesOnMesh(meshName)[1];
readDatak10 = couplingParticipant.getReadDataNamesOnMesh(meshName)[2];
readDatak11 = couplingParticipant.getReadDataNamesOnMesh(meshName)[3];
readDataPorosity = couplingParticipant.getReadDataNamesOnMesh(meshName)[4];
readDatak11 = couplingParticipant.getReadDataNamesOnMesh(meshName)[1];
readDataPorosity = couplingParticipant.getReadDataNamesOnMesh(meshName)[2];
writeDataConcentration = couplingParticipant.getWriteDataNamesOnMesh(meshName)[0];
}

Expand Down Expand Up @@ -191,8 +187,6 @@ int main(int argc, char **argv)
std::vector<double> kInitial(numberOfElements, 1.0);
std::vector<double> porosityInitial(numberOfElements, 0.5);
couplingParticipant.writeQuantityVector(meshName, readDatak00, kInitial);
couplingParticipant.writeQuantityVector(meshName, readDatak01, kInitial);
couplingParticipant.writeQuantityVector(meshName, readDatak10, kInitial);
couplingParticipant.writeQuantityVector(meshName, readDatak11, kInitial);
couplingParticipant.writeQuantityVector(meshName, readDataPorosity,
porosityInitial);
Expand All @@ -211,8 +205,6 @@ int main(int argc, char **argv)
// add model specific output fields
vtkWriter.addField(problem->getPorosity(), "Porosity");
vtkWriter.addField(problem->getK00(), "K00");
vtkWriter.addField(problem->getK01(), "K01");
vtkWriter.addField(problem->getK10(), "K10");
vtkWriter.addField(problem->getK11(), "K11");
problem->updateVtkOutput(x);
vtkWriter.write(0.0);
Expand Down Expand Up @@ -286,10 +278,6 @@ int main(int argc, char **argv)
// and coupling data is interpolated in time
couplingParticipant.readQuantityFromOtherSolver(meshName, readDatak00,
dt);
couplingParticipant.readQuantityFromOtherSolver(meshName, readDatak01,
dt);
couplingParticipant.readQuantityFromOtherSolver(meshName, readDatak10,
dt);
couplingParticipant.readQuantityFromOtherSolver(meshName, readDatak11,
dt);
couplingParticipant.readQuantityFromOtherSolver(meshName,
Expand Down
19 changes: 8 additions & 11 deletions two-scale-heat-conduction/macro-dumux/appl/spatialparams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ public:
{
DimWorldMatrix K;

// Off-diagonal terms of K are always zero because the grain microstructure is circular.
K[0][1] = 0.0;
K[1][0] = 0.0;

if (getParam<bool>("Precice.RunWithCoupling") == true) {
K[0][0] = couplingData_[scv.elementIndex()][1];
K[0][1] = couplingData_[scv.elementIndex()][2];
K[1][0] = couplingData_[scv.elementIndex()][3];
K[1][1] = couplingData_[scv.elementIndex()][4];
K[1][1] = couplingData_[scv.elementIndex()][2];

} else {
K[0][0] = getParam<Scalar>("Component.SolidThermalConductivity");
K[0][1] = 0.0;
K[1][0] = 0.0;
K[1][1] = getParam<Scalar>("Component.SolidThermalConductivity");
}
return K;
Expand All @@ -115,10 +116,6 @@ public:
couplingData_[elementIdx][1] =
couplingParticipant_.getScalarQuantityOnFace("Macro-Mesh", "K00", elementIdx);
couplingData_[elementIdx][2] =
couplingParticipant_.getScalarQuantityOnFace("Macro-Mesh", "K01", elementIdx);
couplingData_[elementIdx][3] =
couplingParticipant_.getScalarQuantityOnFace("Macro-Mesh", "K10", elementIdx);
couplingData_[elementIdx][4] =
couplingParticipant_.getScalarQuantityOnFace("Macro-Mesh", "K11", elementIdx);
}
}
Expand All @@ -131,10 +128,10 @@ public:

private:
Dumux::Precice::CouplingAdapter &couplingParticipant_;
Dune::BlockVector<Dune::FieldVector<double, 5>> couplingData_;
Dune::BlockVector<Dune::FieldVector<double, 3>> couplingData_;
Dumux::VectorCommDataHandleEqual<
typename GridGeometry::ElementMapper,
Dune::BlockVector<Dune::FieldVector<double, 5>>,
Dune::BlockVector<Dune::FieldVector<double, 3>>,
/* Entity codimension = */ 0>
couplingDataHandle_;
};
Expand Down
6 changes: 2 additions & 4 deletions two-scale-heat-conduction/macro-dumux/params.input
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ participant_name = Macro
precice_config_file_path = ../precice-config.xml
interfaces.1.mesh_name = Macro-Mesh
interfaces.1.read_data.1.name = K00
interfaces.1.read_data.2.name = K01
interfaces.1.read_data.3.name = K10
interfaces.1.read_data.4.name = K11
interfaces.1.read_data.5.name = Porosity
interfaces.1.read_data.2.name = K11
interfaces.1.read_data.3.name = Porosity
interfaces.1.write_data.1.name = Concentration
10 changes: 8 additions & 2 deletions two-scale-heat-conduction/macro-nutils/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def main():

# Define Gauss points on entire domain as coupling mesh (volume coupling from macro side)
couplingsample = topo.sample('gauss', degree=2) # mesh vertices are Gauss points
n_gp = couplingsample.eval('x_i' @ ns).shape[0] # number of gauss points
vertex_ids = participant.set_mesh_vertices(mesh_name, couplingsample.eval(ns.x))
else:
sqrphi = topo.integral((ns.phi - phi) ** 2, degree=1)
Expand Down Expand Up @@ -114,10 +115,15 @@ def main():

# Read conductivity and apply it to the existing solution
k_00_c = couplingsample.asfunction(participant.read_data(mesh_name, "K00", vertex_ids, dt))
k_01_c = couplingsample.asfunction(participant.read_data(mesh_name, "K01", vertex_ids, dt))
k_10_c = couplingsample.asfunction(participant.read_data(mesh_name, "K10", vertex_ids, dt))
k_11_c = couplingsample.asfunction(participant.read_data(mesh_name, "K11", vertex_ids, dt))

# Not read from preCICE as the values are zero. Instead, they are set to zero directly.
# k_01_c = couplingsample.asfunction(participant.read_data(mesh_name, "K01", vertex_ids, dt))
# k_10_c = couplingsample.asfunction(participant.read_data(mesh_name, "K10", vertex_ids, dt))

k_01_c = couplingsample.asfunction(np.zeros(n_gp))
k_10_c = couplingsample.asfunction(np.zeros(n_gp))

conductivity = function.asarray([[k_00_c, k_01_c], [k_10_c, k_11_c]])
sqrk = couplingsample.integral(((ns.k - conductivity) * (ns.k - conductivity)).sum([0, 1]))
solk = solver.optimize('solk', sqrk, droptol=1E-12)
Expand Down
6 changes: 0 additions & 6 deletions two-scale-heat-conduction/micro-dumux/appl/micro_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class MicroSimulation {
private:
const double pi_ = 3.14159265358979323846;
double _k_00;
double _k_01;
double _k_10;
double _k_11;
double _porosity;
int sim_id;
Expand Down Expand Up @@ -244,16 +242,12 @@ py::dict MicroSimulation::solve(py::dict macro_write_data, double dt)

// calculate the conductivity tensor
_k_00 = _cpProblem->calculateConductivityTensorComponent(0, 0);
_k_10 = _cpProblem->calculateConductivityTensorComponent(1, 0);
_k_01 = _cpProblem->calculateConductivityTensorComponent(0, 1);
_k_11 = _cpProblem->calculateConductivityTensorComponent(1, 1);

py::dict micro_write_data;

// add micro_scalar_data and micro_vector_data to micro_write_data
micro_write_data["K00"] = _k_00;
micro_write_data["K10"] = _k_10;
micro_write_data["K01"] = _k_01;
micro_write_data["K11"] = _k_11;
micro_write_data["Porosity"] = _porosity;
micro_write_data["Grain-Size"] = std::sqrt((1 - _porosity) / pi_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"participant_name": "Micro-Manager",
"precice_config_file_name": "../precice-config.xml",
"macro_mesh_name": "Macro-Mesh",
"write_data_names": ["K00", "K01", "K10", "K11", "Porosity"],
"write_data_names": ["K00", "K11", "Porosity"],
"read_data_names": ["Concentration"]
},
"simulation_params": {
Expand All @@ -18,7 +18,8 @@
"history_param": 0.1,
"coarsening_constant": 0.2,
"refining_constant": 0.05,
"similarity_measure": "L2rel"
"similarity_measure": "L2rel",
"lazy_initialization": true
}
},
"diagnostics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"participant_name": "Micro-Manager",
"precice_config_file_name": "../precice-config.xml",
"macro_mesh_name": "Macro-Mesh",
"write_data_names": ["K00", "K01", "K10", "K11", "Porosity"],
"write_data_names": ["K00", "K11", "Porosity"],
"read_data_names": ["Concentration"]
},
"simulation_params": {
Expand All @@ -18,7 +18,8 @@
"history_param": 0.1,
"coarsening_constant": 0.2,
"refining_constant": 0.05,
"similarity_measure": "L2rel"
"similarity_measure": "L2rel",
"lazy_initialization": true
}
},
"diagnostics": {
Expand Down
Loading