Skip to content
Snippets Groups Projects
Commit 9e723485 authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[PL] moved some code to separate class

parent 24cdce4b
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,18 @@ ...@@ -16,8 +16,18 @@
#include "NumLib/ODESolver/TimeDiscretization.h" #include "NumLib/ODESolver/TimeDiscretization.h"
#include "NumLib/ODESolver/NonlinearSolver.h" #include "NumLib/ODESolver/NonlinearSolver.h"
#include "DirichletBc.h"
#include "NeumannBc.h"
#include "NeumannBcAssembler.h"
#include "Parameter.h" #include "Parameter.h"
#include "ProcessOutput.h"
#include "ProcessVariable.h" #include "ProcessVariable.h"
#include "UniformDirichletBoundaryCondition.h"
namespace MeshLib
{
class Mesh;
}
namespace ProcessLib namespace ProcessLib
{ {
...@@ -37,15 +47,20 @@ public: ...@@ -37,15 +47,20 @@ public:
using NonlinearSolver = NumLib::NonlinearSolverBase<GlobalMatrix, GlobalVector>; using NonlinearSolver = NumLib::NonlinearSolverBase<GlobalMatrix, GlobalVector>;
using TimeDiscretization = NumLib::TimeDiscretization<GlobalVector>; using TimeDiscretization = NumLib::TimeDiscretization<GlobalVector>;
Process(MeshLib::Mesh& mesh, Process(
NonlinearSolver& nonlinear_solver, MeshLib::Mesh& mesh,
std::unique_ptr<TimeDiscretization>&& time_discretization, NonlinearSolver& nonlinear_solver,
std::vector<std::reference_wrapper<ProcessVariable>>&& std::unique_ptr<TimeDiscretization>&& time_discretization,
process_variables) std::vector<std::reference_wrapper<ProcessVariable>>&& process_variables,
SecondaryVariableCollection<GlobalVector>&& secondary_variables,
ProcessOutput<GlobalVector>&& process_output
)
: _mesh(mesh) : _mesh(mesh)
, _nonlinear_solver(nonlinear_solver) , _nonlinear_solver(nonlinear_solver)
, _time_discretization(std::move(time_discretization)) , _time_discretization(std::move(time_discretization))
, _process_variables(std::move(process_variables)) , _process_variables(std::move(process_variables))
, _process_output(std::move(process_output))
, _secondary_variables(std::move(secondary_variables))
{} {}
/// Preprocessing before starting assembly for new timestep. /// Preprocessing before starting assembly for new timestep.
...@@ -61,48 +76,8 @@ public: ...@@ -61,48 +76,8 @@ public:
const unsigned /*timestep*/, const unsigned /*timestep*/,
GlobalVector const& x) const GlobalVector const& x) const
{ {
DBUG("Process output."); doProcessOutput(file_name, x, _mesh, *_local_to_global_index_map,
_process_variables, _secondary_variables, _process_output);
// Copy result
#ifdef USE_PETSC
// TODO It is also possible directly to copy the data for single process
// variable to a mesh property. It needs a vector of global indices and
// some PETSc magic to do so.
std::vector<double> x_copy(x.getLocalSize() + x.getGhostSize());
#else
std::vector<double> x_copy(x.size());
#endif
x.copyValues(x_copy);
std::size_t const n_nodes = _mesh.getNNodes();
for (ProcessVariable& pv : _process_variables)
{
auto& output_data = pv.getOrCreateMeshProperty();
int const n_components = pv.getNumberOfComponents();
for (std::size_t node_id = 0; node_id < n_nodes; ++node_id)
{
MeshLib::Location const l(_mesh.getID(),
MeshLib::MeshItemType::Node, node_id);
// TODO extend component ids to multiple process variables.
for (int component_id = 0; component_id < n_components;
++component_id)
{
auto const index =
_local_to_global_index_map->getLocalIndex(
l, component_id, x.getRangeBegin(),
x.getRangeEnd());
output_data[node_id * n_components + component_id] =
x_copy[index];
}
}
}
// Write output file
DBUG("Writing output to \'%s\'.", file_name.c_str());
MeshLib::IO::VtuInterface vtu_interface(&_mesh, vtkXMLWriter::Binary, true);
vtu_interface.writeToFile(file_name);
} }
void initialize() void initialize()
...@@ -117,7 +92,8 @@ public: ...@@ -117,7 +92,8 @@ public:
computeSparsityPattern(); computeSparsityPattern();
#endif #endif
createAssemblers(*_local_to_global_index_map, _mesh, _integration_order); initializeConcreteProcess(*_local_to_global_index_map, _mesh,
_integration_order);
DBUG("Initialize boundary conditions."); DBUG("Initialize boundary conditions.");
for (ProcessVariable& pv : _process_variables) for (ProcessVariable& pv : _process_variables)
...@@ -203,7 +179,7 @@ public: ...@@ -203,7 +179,7 @@ public:
private: private:
/// Process specific initialization called by initialize(). /// Process specific initialization called by initialize().
virtual void createAssemblers( virtual void initializeConcreteProcess(
AssemblerLib::LocalToGlobalIndexMap const& dof_table, AssemblerLib::LocalToGlobalIndexMap const& dof_table,
MeshLib::Mesh const& mesh, MeshLib::Mesh const& mesh,
unsigned const integration_order) = 0; unsigned const integration_order) = 0;
...@@ -326,7 +302,6 @@ private: ...@@ -326,7 +302,6 @@ private:
unsigned const _integration_order = 2; unsigned const _integration_order = 2;
MeshLib::Mesh& _mesh; MeshLib::Mesh& _mesh;
std::unique_ptr<MeshLib::MeshSubset const> _mesh_subset_all_nodes;
std::unique_ptr<AssemblerLib::LocalToGlobalIndexMap> std::unique_ptr<AssemblerLib::LocalToGlobalIndexMap>
_local_to_global_index_map; _local_to_global_index_map;
...@@ -341,6 +316,12 @@ private: ...@@ -341,6 +316,12 @@ private:
/// Variables used by this process. /// Variables used by this process.
std::vector<std::reference_wrapper<ProcessVariable>> _process_variables; std::vector<std::reference_wrapper<ProcessVariable>> _process_variables;
ProcessOutput<GlobalVector> _process_output;
protected:
std::unique_ptr<MeshLib::MeshSubset const> _mesh_subset_all_nodes;
SecondaryVariableCollection<GlobalVector> _secondary_variables;
}; };
/// Find process variables in \c variables whose names match the settings under /// Find process variables in \c variables whose names match the settings under
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment