12 #if !defined(KRATOS_BFECC_CONVECTION_INCLUDED )
13 #define KRATOS_BFECC_CONVECTION_INCLUDED
15 #define PRESSURE_ON_EULERIAN_MESH
16 #define USE_FEW_PARTICLES
28 #include "utilities/geometry_utilities.h"
42 template<std::
size_t TDim>
50 const bool PartialDt =
false,
51 const bool ActivateLimiter =
false)
52 : mpSearchStructure(pSearchStructure), mActivateLimiter(ActivateLimiter)
66 const double substeps)
74 const int max_results = 10000;
77 const int nparticles = rModelPart.
Nodes().size();
80 std::vector< Vector > Ns( rModelPart.
Nodes().size());
81 std::vector< bool > found( rModelPart.
Nodes().size());
85 rNode.SetValue(rVar, 0.0);
89 if (mActivateLimiter){
92 for (
int i = 0;
i < nparticles;
i++){
98 #pragma omp parallel for firstprivate(results,N,N_valid)
99 for (
int i = 0;
i < nparticles;
i++)
103 ModelPart::NodesContainerType::iterator it_particle = rModelPart.
NodesBegin() +
i;
105 Element::Pointer pelement;
106 Element::Pointer pelement_valid;
110 bool has_valid_elem_pointer =
false;
111 bool is_found =
ConvectBySubstepping(
dt,bckPos,
vel,
N,N_valid, pelement,pelement_valid, result_begin, max_results, -1.0, substeps, conv_var, has_valid_elem_pointer);
116 elem_backward(
i) = pelement;
120 double phi1 =
N[0] * ( geom[0].FastGetSolutionStepValue(rVar,1));
121 for (
unsigned int k = 1;
k < geom.
size();
k++) {
122 phi1 +=
N[
k] * ( geom[
k].FastGetSolutionStepValue(rVar,1) );
125 it_particle->FastGetSolutionStepValue(rVar) = phi1;
127 else if(has_valid_elem_pointer)
130 elem_backward(
i) = pelement_valid;
134 double phi1 =
N[0] * ( geom[0].FastGetSolutionStepValue(rVar,1));
135 for (
unsigned int k = 1;
k < geom.
size();
k++) {
136 phi1 += N_valid[
k] * ( geom[
k].FastGetSolutionStepValue(rVar,1) );
139 it_particle->FastGetSolutionStepValue(rVar) = phi1;
144 #pragma omp parallel for firstprivate(results,N,N_valid)
145 for (
int i = 0;
i < nparticles;
i++)
149 ModelPart::NodesContainerType::iterator it_particle = rModelPart.
NodesBegin() +
i;
151 Element::Pointer pelement;
152 Element::Pointer pelement_valid;
156 bool has_valid_elem_pointer =
false;
157 bool is_found =
ConvectBySubstepping(
dt,fwdPos,
vel,
N, N_valid, pelement, pelement_valid, result_begin, max_results, 1.0, substeps, conv_var,has_valid_elem_pointer);
161 double phi_old =
N[0] * ( geom[0].FastGetSolutionStepValue(rVar));
163 for (
unsigned int k = 1;
k < geom.
size();
k++) {
164 phi_old +=
N[
k] * ( geom[
k].FastGetSolutionStepValue(rVar) );
168 const auto limiter_factor = 0.5*
mLimiter[
i];
169 it_particle->GetValue(rVar) = (1.0 + limiter_factor)*it_particle->FastGetSolutionStepValue(rVar,1) - limiter_factor*
phi_old;
174 it_particle->GetValue(rVar) = it_particle->FastGetSolutionStepValue(rVar,1);
178 #pragma omp parallel for
179 for (
int i = 0;
i < nparticles;
i++)
181 ModelPart::NodesContainerType::iterator it_particle = rModelPart.
NodesBegin() +
i;
182 bool is_found = found[
i];
186 double phi1 =
N[0] * ( geom[0].
GetValue(rVar));
187 for (
unsigned int k = 1;
k < geom.
size();
k++) {
191 it_particle->FastGetSolutionStepValue(rVar) = phi1;
206 Element::Pointer& pelement,
207 Element::Pointer& pelement_valid,
209 const unsigned int max_results,
210 const double velocity_sign,
211 const double subdivisions,
213 bool& has_valid_elem_pointer)
215 bool is_found =
false;
217 const double small_dt =
dt/subdivisions;
219 if(velocity_sign > 0.0)
221 noalias(position) += small_dt*initial_velocity;
222 unsigned int substep=0;
223 while(substep++ < subdivisions)
225 is_found = mpSearchStructure->FindPointOnMesh(position,
N, pelement, result_begin, max_results);
227 if (is_found ==
true)
231 const double new_step_factor =
static_cast<double>(substep)/subdivisions;
232 const double old_step_factor = (1.0 - new_step_factor);
234 noalias(veulerian) =
N[0] * ( new_step_factor*geom[0].FastGetSolutionStepValue(conv_var) + old_step_factor*geom[0].FastGetSolutionStepValue(conv_var,1));
235 for (
unsigned int k = 1;
k < geom.
size();
k++)
236 noalias(veulerian) +=
N[
k] * ( new_step_factor*geom[
k].FastGetSolutionStepValue(conv_var) + old_step_factor*geom[
k].FastGetSolutionStepValue(conv_var,1) );
238 noalias(position) += small_dt*veulerian;
241 pelement_valid = pelement;
242 has_valid_elem_pointer =
true;
251 noalias(position) -= small_dt*initial_velocity;
252 unsigned int substep=0;
253 while(substep++ < subdivisions)
255 is_found = mpSearchStructure->FindPointOnMesh(position,
N, pelement, result_begin, max_results);
257 if (is_found ==
true)
262 const double old_step_factor =
static_cast<double>(substep)/subdivisions;
263 const double new_step_factor = (1.0 - old_step_factor);
265 noalias(veulerian) =
N[0] * ( new_step_factor*geom[0].FastGetSolutionStepValue(conv_var) + old_step_factor*geom[0].FastGetSolutionStepValue(conv_var,1));
266 for (
unsigned int k = 1;
k < geom.
size();
k++)
267 noalias(veulerian) +=
N[
k] * ( new_step_factor*geom[
k].FastGetSolutionStepValue(conv_var) + old_step_factor*geom[
k].FastGetSolutionStepValue(conv_var,1) );
269 noalias(position) -= small_dt*veulerian;
272 pelement_valid = pelement;
273 has_valid_elem_pointer =
true;
293 const double epsilon = 1.0e-15;
294 const double power = 2.0;
296 const int nparticles = rModelPart.
Nodes().size();
298 if(
static_cast<int>(
mSigmaPlus.size()) != nparticles){
306 for (
int i_node = 0; i_node < static_cast<int>(rModelPart.
NumberOfNodes()); ++i_node){
307 auto it_node = rModelPart.
NodesBegin() + i_node;
310 for (
unsigned int j = 0;
j< global_pointer_list.
size(); ++
j)
312 auto& global_pointer = global_pointer_list(
j);
319 auto coordinate_proxy = pointer_comm.
Apply(
322 return global_pointer->Coordinates();
326 auto distance_proxy = pointer_comm.
Apply(
329 return global_pointer->FastGetSolutionStepValue(rVar);
335 auto it_node = rModelPart.
NodesBegin() + i_node;
336 const auto& X_i = it_node->Coordinates();
337 const auto& grad_i = it_node->GetValue(DISTANCE_GRADIENT);
340 double S_minus = 0.0;
344 for (
unsigned int j = 0;
j< global_pointer_list.
size(); ++
j)
350 auto& global_pointer = global_pointer_list(
j);
351 auto X_j = coordinate_proxy.Get(global_pointer);
364 auto it_node = rModelPart.
NodesBegin() + i_node;
365 const double distance_i = it_node->FastGetSolutionStepValue(rVar);
366 const auto& X_i = it_node->Coordinates();
367 const auto& grad_i = it_node->GetValue(DISTANCE_GRADIENT);
369 double numerator = 0.0;
370 double denominator = 0.0;
374 for (
unsigned int j = 0;
j< global_pointer_list.
size(); ++
j)
380 auto& global_pointer = global_pointer_list(
j);
381 auto X_j = coordinate_proxy.Get(global_pointer);
382 const double distance_j = distance_proxy.Get(global_pointer);
384 double beta_ij = 1.0;
390 numerator += beta_ij*(distance_i - distance_j);
391 denominator += beta_ij*std::abs(distance_i - distance_j);
394 const double fraction = (std::abs(numerator)) / (denominator + epsilon);
405 ModelPart::NodesContainerType::iterator inodebegin = rModelPart.
NodesBegin();
406 vector<int> node_partition;
408 int number_of_threads = omp_get_max_threads();
410 int number_of_threads = 1;
412 OpenMPUtils::CreatePartition(number_of_threads, rModelPart.
Nodes().size(), node_partition);
414 #pragma omp parallel for
415 for(
int kkk=0; kkk<number_of_threads; kkk++)
417 for(
int ii=node_partition[kkk]; ii<node_partition[kkk+1]; ii++)
419 ModelPart::NodesContainerType::iterator inode = inodebegin+ii;
421 if (inode->IsFixed(rVar))
423 inode->FastGetSolutionStepValue(rVar)=inode->GetSolutionStepValue(rVar,1);
434 ModelPart::NodesContainerType::iterator inodebegin = rModelPart.
NodesBegin();
435 vector<int> node_partition;
437 int number_of_threads = omp_get_max_threads();
439 int number_of_threads = 1;
441 OpenMPUtils::CreatePartition(number_of_threads, rModelPart.
Nodes().size(), node_partition);
443 #pragma omp parallel for
444 for(
int kkk=0; kkk<number_of_threads; kkk++)
446 for(
int ii=node_partition[kkk]; ii<node_partition[kkk+1]; ii++)
448 ModelPart::NodesContainerType::iterator inode = inodebegin+ii;
449 inode->GetSolutionStepValue(rVar,1) = inode->FastGetSolutionStepValue(rVar);
461 const bool mActivateLimiter;
Definition: bfecc_convection.h:44
void CopyScalarVarToPreviousTimeStep(ModelPart &rModelPart, const Variable< double > &rVar)
Definition: bfecc_convection.h:431
~BFECCConvection()
Definition: bfecc_convection.h:56
void BFECCconvect(ModelPart &rModelPart, const Variable< double > &rVar, const Variable< array_1d< double, 3 > > &conv_var, const double substeps)
Definition: bfecc_convection.h:62
Kratos::Vector mSigmaPlus
Definition: bfecc_convection.h:456
KRATOS_CLASS_POINTER_DEFINITION(BFECCConvection< TDim >)
Kratos::Vector mSigmaMinus
Definition: bfecc_convection.h:456
Kratos::Vector mLimiter
Definition: bfecc_convection.h:456
void CalculateLimiter(ModelPart &rModelPart, const Variable< double > &rVar)
Definition: bfecc_convection.h:289
BFECCConvection(typename BinBasedFastPointLocator< TDim >::Pointer pSearchStructure, const bool PartialDt=false, const bool ActivateLimiter=false)
Definition: bfecc_convection.h:48
bool ConvectBySubstepping(const double dt, array_1d< double, 3 > &position, const array_1d< double, 3 > &initial_velocity, Vector &N, Vector &N_valid, Element::Pointer &pelement, Element::Pointer &pelement_valid, typename BinBasedFastPointLocator< TDim >::ResultIteratorType &result_begin, const unsigned int max_results, const double velocity_sign, const double subdivisions, const Variable< array_1d< double, 3 > > &conv_var, bool &has_valid_elem_pointer)
Definition: bfecc_convection.h:200
void ResetBoundaryConditions(ModelPart &rModelPart, const Variable< double > &rVar)
Definition: bfecc_convection.h:401
This class is designed to allow the fast location of MANY points on the top of a 3D mesh.
Definition: binbased_fast_point_locator.h:68
ConfigureType::ResultIteratorType ResultIteratorType
Definition: binbased_fast_point_locator.h:82
ConfigureType::ResultContainerType ResultContainerType
Definition: binbased_fast_point_locator.h:81
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
A template class for handling communication related to global pointers.
Definition: pointer_communicator.h:178
ResultsProxy< TPointerDataType, TFunctorType > Apply(TFunctorType &&UserFunctor)
Applies a user-provided function to the global pointers and return a proxy to the results.
Definition: pointer_communicator.h:266
This class is a wrapper for a pointer to a data that is located in a different rank.
Definition: global_pointer.h:44
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
void push_back(TPointerType x)
Definition: global_pointers_vector.h:322
size_type size() const
Definition: global_pointers_vector.h:307
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
dt
Definition: DEM_benchmarks.py:173
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
list fraction
Definition: angle_finder.py:11
phi_old
Definition: generate_convection_diffusion_explicit_element.py:103
vel
Definition: pure_conduction.py:76
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17