12 #if !defined(KRATOS_DISTRIBUTED_SYSTEM_VECTOR_H_INCLUDED )
13 #define KRATOS_DISTRIBUTED_SYSTEM_VECTOR_H_INCLUDED
59 template<
class TDataType=
double,
class TIndexType=std::
size_t>
81 mpNumbering = Kratos::make_unique< DistributedNumbering<IndexType> >( rGraph.
GetRowNumbering());
83 mLocalData.resize(rGraph.
LocalSize(),
false);
88 for(
IndexType cpu_id=0; cpu_id < r_non_local_graphs.size(); cpu_id++)
90 const auto& graph = r_non_local_graphs[cpu_id];
91 for(
auto item=graph.begin(); item!=graph.end(); ++item)
94 mNonLocalData[global_id] = TDataType();
104 mpNumbering = Kratos::make_unique<DistributedNumbering<IndexType>>(rOther.
GetNumbering());
108 mLocalData.resize(rOther.
LocalSize(),
false);
110 (mLocalData)[
i] = rOther[
i];
112 mNonLocalData = rOther.mNonLocalData;
113 if(rOther.mpexporter !=
nullptr)
114 mpexporter = Kratos::make_unique<DistributedVectorExporter<IndexType>>(rOther.
GetExporter());
122 mpNumbering = Kratos::make_unique< DistributedNumbering<IndexType> >( rNumbering );
123 mLocalData.resize(rNumbering.
LocalSize(),
false);
153 mLocalData[
i] = value;
158 return mLocalData[I];
163 return mLocalData[I];
167 return mLocalData[I];
171 return mLocalData[I];
175 return mpNumbering->
Size();
191 KRATOS_DEBUG_ERROR_IF(mpexporter==
nullptr) <<
" mpexporter was not initialized, GetExporter() cannot be used" << std::endl;
199 mNonLocalData[GlobalI] = TDataType();
203 template<
class TIteratorType>
204 void AddEntries(TIteratorType it_begin, TIteratorType it_end)
206 for(TIteratorType it=it_begin; it!=it_end; ++it)
214 return mLocalData[
i]*other_data[
i];
217 dot_value =
GetComm().Sum(dot_value, gather_on_rank);
218 if(
GetComm().Rank() != gather_on_rank) dot_value = -1;
228 <<
" " <<
" rOtherVector.LocalSize() " << rOtherVector.
LocalSize() << std::endl;
231 (mLocalData)[
i] +=
factor*rOtherVector.mLocalData[
i];
238 <<
" " <<
" rOtherVector.LocalSize() " << rOtherVector.
LocalSize() << std::endl;
240 (mLocalData)[
i] = rOtherVector.mLocalData[
i];
249 <<
" " <<
" rOtherVector.LocalSize() " << rOtherVector.
LocalSize() << std::endl;
251 (mLocalData)[
i] += rOtherVector.mLocalData[
i];
259 <<
" " <<
" rOtherVector.LocalSize() " << rOtherVector.
LocalSize() << std::endl;
261 (mLocalData)[
i] -= rOtherVector.mLocalData[
i];
269 (mLocalData)[
i] *= multiplier_factor;
277 (mLocalData)[
i] /= divide_factor;
290 for(
auto & item : mNonLocalData)
292 non_local_global_ids[
counter] = item.first;
296 auto ptmp = Kratos::make_unique< DistributedVectorExporter<TIndexType> >(
GetComm(), non_local_global_ids,
GetNumbering());
297 mpexporter.swap(ptmp);
306 for(
auto & item : mNonLocalData)
308 non_local_data[
counter] = item.second;
312 mpexporter->Apply(*
this,non_local_data);
315 template<
class TVectorType,
class TIndexVectorType >
317 const TVectorType& rVectorInput,
318 const TIndexVectorType& EquationId
323 for(
unsigned int i=0;
i<EquationId.size(); ++
i){
329 AtomicAdd(mLocalData(local_i) , rVectorInput[
i]);
333 auto it = (mNonLocalData.find( global_i ));
334 KRATOS_DEBUG_ERROR_IF(it == mNonLocalData.end()) <<
"global_i = "<< global_i <<
" not in mNonLocalData. Please note that the mNonLocalData structure is assumed fixed after InitializeAssemble is called" << std::endl;
335 TDataType& value = (*it).second;
358 std::stringstream buffer;
359 buffer <<
"DistributedSystemVector" ;
366 rOStream <<
"DistributedSystemVector LOCAL DATA:" << std::endl;
374 std::cout << mLocalData << std::endl;
433 std::unordered_map<IndexType, TDataType> mNonLocalData;
478 template<
class TDataType,
class TIndexType>
486 template<
class TDataType,
class TIndexType>
491 rOStream << std::endl;
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
IndexType LocalSize() const
Definition: distributed_numbering.h:161
IndexType RemoteGlobalId(const IndexType rRemoteLocalId, const IndexType rOwnerRank) const
Definition: distributed_numbering.h:195
IndexType LocalId(const IndexType rGlobalId) const
Definition: distributed_numbering.h:178
const std::vector< IndexType > & GetCpuBounds() const
Definition: distributed_numbering.h:215
IndexType Size() const
Definition: distributed_numbering.h:167
Short class definition.
Definition: distributed_sparse_graph.h:68
const DenseVector< NonLocalGraphType > & GetNonLocalGraphs() const
Definition: distributed_sparse_graph.h:295
const DistributedNumbering< IndexType > & GetRowNumbering() const
Definition: distributed_sparse_graph.h:111
IndexType LocalSize() const
Definition: distributed_sparse_graph.h:121
Provides a DistributedSystemVector which implements FEM assemble capabilities.
Definition: distributed_system_vector.h:61
TDataType value_type
Definition: distributed_system_vector.h:65
TDataType & operator[](IndexType I)
Definition: distributed_system_vector.h:166
void Add(const TDataType factor, const DistributedSystemVector &rOtherVector)
Definition: distributed_system_vector.h:223
const DataCommunicator & GetComm() const
Definition: distributed_system_vector.h:132
void FinalizeAssemble()
Definition: distributed_system_vector.h:301
DistributedSystemVector & operator+=(const DistributedSystemVector &rOtherVector)
Definition: distributed_system_vector.h:246
IndexType LocalSize() const
Definition: distributed_system_vector.h:178
TDataType & operator()(IndexType I)
Definition: distributed_system_vector.h:157
TDataType Dot(const DistributedSystemVector &rOtherVector, MpiIndexType gather_on_rank=0)
Definition: distributed_system_vector.h:210
TIndexType IndexType
Definition: distributed_system_vector.h:66
DenseVector< TDataType > & GetLocalData()
Definition: distributed_system_vector.h:182
DistributedSystemVector(const DistributedSparseGraph< IndexType > &rGraph)
Definition: distributed_system_vector.h:77
~DistributedSystemVector()
Destructor.
Definition: distributed_system_vector.h:127
void AddEntry(TIndexType GlobalI)
Definition: distributed_system_vector.h:196
void BeginAssemble()
Definition: distributed_system_vector.h:285
DistributedSystemVector & operator=(DistributedSystemVector const &rOtherVector)
Assignment operator.
Definition: distributed_system_vector.h:236
std::string Info() const
Turn back information as a string.
Definition: distributed_system_vector.h:356
IndexType Size() const
Definition: distributed_system_vector.h:174
void Assemble(const TVectorType &rVectorInput, const TIndexVectorType &EquationId)
Definition: distributed_system_vector.h:316
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: distributed_system_vector.h:370
DistributedSystemVector(DistributedSystemVector const &rOther)
Copy constructor.
Definition: distributed_system_vector.h:100
const DistributedNumbering< IndexType > & GetNumbering() const
Definition: distributed_system_vector.h:140
const DistributedVectorExporter< TIndexType > & GetExporter() const
Definition: distributed_system_vector.h:190
const DataCommunicator * pGetComm() const
Definition: distributed_system_vector.h:136
DistributedSystemVector & operator-=(const DistributedSystemVector &rOtherVector)
Definition: distributed_system_vector.h:256
KRATOS_CLASS_POINTER_DEFINITION(DistributedSystemVector)
Pointer definition of DistributedSystemVector.
const DenseVector< TDataType > & GetLocalData() const
Definition: distributed_system_vector.h:186
DistributedSystemVector & operator*=(const TDataType &multiplier_factor)
Definition: distributed_system_vector.h:266
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: distributed_system_vector.h:364
DistributedSystemVector(const DistributedNumbering< IndexType > &rNumbering)
Definition: distributed_system_vector.h:118
const TDataType & operator[](IndexType I) const
Definition: distributed_system_vector.h:170
void SetValue(const TDataType value)
Definition: distributed_system_vector.h:150
DistributedSystemVector & operator/=(const TDataType ÷_factor)
Definition: distributed_system_vector.h:274
const TDataType & operator()(IndexType I) const
Definition: distributed_system_vector.h:162
void Clear()
Definition: distributed_system_vector.h:145
void AddEntries(TIteratorType it_begin, TIteratorType it_end)
Definition: distributed_system_vector.h:204
int MpiIndexType
Definition: distributed_system_vector.h:67
Provides a DistributedVectorExporter which implements FEM assemble capabilities.
Definition: distributed_vector_exporter.h:54
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
Definition: amatrix_interface.h:41
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void AtomicAdd(TDataType &target, const TDataType &value)
Definition: atomic_utilities.h:55
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int k
Definition: quadrature.py:595
int counter
Definition: script_THERMAL_CORRECT.py:218
integer i
Definition: TensorModule.f:17
float factor
for node in (self.combined_model_part).Nodes: pold = node.GetSolutionStepValue(PRESSURE,...
Definition: ulf_PGLASS.py:254