12 #if !defined(KRATOS_PURE_CONVECTION_CRANKN_UTILITIES_INCLUDED )
13 #define KRATOS_PURE_CONVECTION_CRANKN_UTILITIES_INCLUDED
26 #include "utilities/geometry_utilities.h"
32 template<
int TDim,
class TSparseSpace,
class TLinearSolver>
62 if( (it->GetValue(NEIGHBOUR_NODES)).size() != 0 )
64 mDofSet.
push_back( it->pGetDof(rScalarVar) );
66 tot_nnz += (it->GetValue(NEIGHBOUR_NODES)).size()+1;
73 int fix_id = mDofSet.
size();
76 if (dof_iterator->IsFixed())
77 dof_iterator->SetEquationId(--fix_id);
79 dof_iterator->SetEquationId(free_id++);
81 mEquationSystemSize = fix_id;
83 std::vector< int > work_array;
84 work_array.reserve(1000);
87 mA.resize(mEquationSystemSize, mEquationSystemSize, tot_nnz);
96 unsigned int index_i = it->GetDof(rScalarVar).EquationId();
98 if(index_i < mEquationSystemSize && (it->GetValue(NEIGHBOUR_NODES)).size() != 0)
106 unsigned int index_j =
i->GetDof(rScalarVar).EquationId();
107 if(index_j < mEquationSystemSize)
108 work_array.push_back(index_j);
112 std::sort(work_array.begin(),work_array.end());
113 typename std::vector<int>::iterator new_end = std::unique(work_array.begin(),work_array.end());
114 unsigned int number_of_entries = new_end - work_array.begin();
117 for(
unsigned int j=0;
j<number_of_entries;
j++)
119 mA.push_back(index_i,work_array[
j] , 0.00);
123 work_array.erase(work_array.begin(),work_array.end());
129 mDx.resize(mA.size1(),
false);
130 mb.resize(mA.size1(),
false);
137 typename TLinearSolver::Pointer linear_solver,
146 TSparseSpace::SetToZero(mA);
147 TSparseSpace::SetToZero(mb);
148 TSparseSpace::SetToZero(mDx);
151 double dt = CurrentProcessInfo[DELTA_TIME];
158 BDFcoeffs[0] = 1.0 /
dt;
159 BDFcoeffs[1] = -1.0 /
dt;
163 KRATOS_WATCH(
"CONVECTION: CrankNicholson.......................................................................................");
183 for(
unsigned int i=0;
i<TDim+1;
i++)
184 MassFactors[
i] = 1.0/
double(TDim+1);
189 double lumping_factor = 1.0/
double(TDim+1.0);
190 const unsigned int number_of_points = TDim+1;
193 for(ModelPart::ElementsContainerType::iterator
i =
model_part.ElementsBegin();
203 for(
int ii = 0; ii<TDim+1; ii++)
205 local_indices[ii] = geom[ii].GetDof(rScalarVar).EquationId();
215 double proj_old = 0.0;
216 for(
unsigned int i = 0;
i<number_of_points;
i++)
222 proj += geom[
i].FastGetSolutionStepValue(rProjVar);
223 proj_old += geom[
i].FastGetSolutionStepValue(rProjVar,1);
224 for(
unsigned int j = 0;
j<TDim;
j++)
226 vel_gauss[
j] +=
v[
j] -
w[
j];
227 vel_gauss_old[
j] += v_old[
j] - w_old[
j];
231 vel_gauss += vel_gauss_old;
232 vel_gauss *= lumping_factor*0.5;
236 proj *= lumping_factor*0.5;
249 double tau = CalculateTAU(vel_gauss,Volume);
255 for(
unsigned int iii = 0; iii<number_of_points; iii++)
257 lhs_contribution(iii,iii) += BDFcoeffs[0] * MassFactors[iii];
271 for(
unsigned int iii = 0; iii<number_of_points; iii++)
273 temp_vec_np[iii] = BDFcoeffs[1]*geom[iii].FastGetSolutionStepValue(rScalarVar,1);
276 for(
unsigned int iii = 0; iii<number_of_points; iii++)
277 rhs_contribution[iii] -= MassFactors[iii]*temp_vec_np[iii];
283 for(
unsigned int iii = 0; iii<number_of_points; iii++)
285 temp_vec_np[iii] = geom[iii].FastGetSolutionStepValue(rScalarVar)+geom[iii].FastGetSolutionStepValue(rScalarVar,1);
287 noalias(rhs_contribution) -=
prod(lhs_contribution,temp_vec_np);
291 for(
unsigned int iii = 0; iii<number_of_points; iii++)
293 rhs_contribution[iii] += MassFactors[iii]*BDFcoeffs[0]*geom[iii].FastGetSolutionStepValue(rScalarVar,1);
302 rhs_contribution *= Volume;
303 lhs_contribution *= Volume;
305 AssembleLHS(mA,lhs_contribution,local_indices);
306 AssembleRHS(mb,rhs_contribution,local_indices);
320 linear_solver->Solve(mA,mDx,mb);
321 std::cout << *(linear_solver) << std::endl;
331 i_dof->GetSolutionStepValue() += mDx[i_dof->EquationId()];
363 double lumping_factor = 1.0/
double(TDim+1.0);
364 const unsigned int number_of_points = TDim+1;
367 for(ModelPart::NodesContainerType::iterator
i =
model_part.NodesBegin();
370 i->FastGetSolutionStepValue(rNodalArea) = 0.0;
371 i->FastGetSolutionStepValue(rProjVar) = 0.0;
376 for(ModelPart::ElementsContainerType::iterator
i =
model_part.ElementsBegin();
387 double nodal_area = Volume*lumping_factor;
389 for(
unsigned int i = 0;
i<number_of_points;
i++)
395 geom[
i].FastGetSolutionStepValue(rNodalArea) += nodal_area;
397 for(
unsigned int j = 0;
j<TDim;
j++)
399 vel_gauss[
j] +=
v[
j] -
w[
j];
402 vel_gauss *= lumping_factor;
405 for(
unsigned int iii = 0; iii<number_of_points; iii++)
406 temp_vec_np[iii] = geom[iii].FastGetSolutionStepValue(rScalarVar);
410 double conv_proj =
inner_prod( u_DN , temp_vec_np);
411 conv_proj *= Volume * lumping_factor;
413 for(
unsigned int iii = 0; iii<number_of_points; iii++)
414 geom[iii].FastGetSolutionStepValue(rProjVar) += conv_proj;
418 for(ModelPart::NodesContainerType::iterator
i =
model_part.NodesBegin();
421 i->FastGetSolutionStepValue(rProjVar) /=
i->FastGetSolutionStepValue(rNodalArea);
434 mA.resize(0,0,
false);
444 unsigned int mEquationSystemSize;
461 unsigned int local_size = LHS_Contribution.size1();
463 for (
unsigned int i_local=0; i_local<
local_size; i_local++)
465 unsigned int i_global=EquationId[i_local];
466 if ( i_global < mEquationSystemSize )
468 for (
unsigned int j_local=0; j_local<
local_size; j_local++)
470 unsigned int j_global=EquationId[j_local];
471 if ( j_global < mEquationSystemSize )
472 A(i_global,j_global) += LHS_Contribution(i_local,j_local);
483 const array_1d<double,TDim+1>& RHS_Contribution,
484 const array_1d<unsigned int,TDim+1>& EquationId
487 unsigned int local_size = RHS_Contribution.size();
489 for (
unsigned int i_local=0; i_local<
local_size; i_local++)
491 unsigned int i_global=EquationId[i_local];
492 if ( i_global < mEquationSystemSize )
495 b[i_global] += RHS_Contribution[i_local];
501 double CalculateTAU(
const array_1d<double,2>&
vel,
const double& Volume)
506 double h = sqrt(2.00*Volume);
509 return h / ( c2*norm_u );
513 double CalculateTAU(
const array_1d<double,3>&
vel,
const double& Volume)
518 double h = pow(6.00*Volume,0.3333333);
521 return h / ( c2*norm_u );
Geometry base class.
Definition: geometry.h:71
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
void push_back(TPointerType x)
Definition: global_pointers_vector.h:322
iterator begin()
Definition: global_pointers_vector.h:221
iterator end()
Definition: global_pointers_vector.h:229
This object defines an indexed object.
Definition: indexed_object.h:54
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
void clear()
Clear the set, removing all elements.
Definition: pointer_vector_set.h:663
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
void reserve(int reservedsize)
Reserves memory for a specified number of elements.
Definition: pointer_vector_set.h:733
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Definition: pure_convection_CrankN_tools.h:34
PointerVectorSet< Dof< double >, IndexedObject > DofsArrayType
Definition: pure_convection_CrankN_tools.h:39
TSparseSpace::MatrixType TSystemMatrixType
Definition: pure_convection_CrankN_tools.h:37
void ConvectScalarVar(ModelPart &model_part, typename TLinearSolver::Pointer linear_solver, Variable< double > &rScalarVar, const Variable< array_1d< double, 3 > > &rTransportVel, const Variable< array_1d< double, 3 > > &rMeshVel, const Variable< double > &rProjVar, unsigned int time_order)
Definition: pure_convection_CrankN_tools.h:136
TSparseSpace::VectorType TSystemVectorType
Definition: pure_convection_CrankN_tools.h:38
void CalculateProjection(ModelPart &model_part, const Variable< double > &rScalarVar, const Variable< double > &rNodalArea, const Variable< array_1d< double, 3 > > &rTransportVel, const Variable< array_1d< double, 3 > > &rMeshVel, Variable< double > &rProjVar)
Definition: pure_convection_CrankN_tools.h:344
void ConstructSystem(ModelPart &model_part, Variable< double > &rScalarVar, Variable< array_1d< double, 3 > > &rTransportVel, Variable< array_1d< double, 3 > > &rMeshVel)
Definition: pure_convection_CrankN_tools.h:49
void ClearSystem()
Definition: pure_convection_CrankN_tools.h:427
~PureConvectionCrankNUtilities()
Definition: pure_convection_CrankN_tools.h:43
PureConvectionCrankNUtilities()
Definition: pure_convection_CrankN_tools.h:42
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
dt
Definition: DEM_benchmarks.py:173
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
AMatrix::VectorOuterProductExpression< TExpression1Type, TExpression2Type > outer_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:582
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
int time_order
Definition: ProjectParameters.py:51
model_part
Definition: face_heat.py:14
v
Definition: generate_convection_diffusion_explicit_element.py:114
w
Definition: generate_convection_diffusion_explicit_element.py:108
tau
Definition: generate_convection_diffusion_explicit_element.py:115
h
Definition: generate_droplet_dynamics.py:91
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
vel
Definition: pure_conduction.py:76
int j
Definition: quadrature.py:648
A
Definition: sensitivityMatrix.py:70
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31