| 153 | } |
| 154 | |
| 155 | void VariableTensorAdaptor::StoreData() |
| 156 | { |
| 157 | std::visit([this](auto pContainer, auto pVariable) { |
| 158 | using container_type = BareType<decltype(*pContainer)>; |
| 159 | |
| 160 | if constexpr(IsInList<container_type, |
| 161 | ModelPart::NodesContainerType, |
| 162 | ModelPart::ConditionsContainerType, |
| 163 | ModelPart::ElementsContainerType, |
| 164 | ModelPart::PropertiesContainerType, |
| 165 | ModelPart::MasterSlaveConstraintContainerType, |
| 166 | ModelPart::GeometryContainerType>) { |
| 167 | |
| 168 | using variable_type = BareType<decltype(*pVariable)>; |
| 169 | using data_type = typename variable_type::Type; |
| 170 | |
| 171 | const auto& r_tensor_shape = this->Shape(); |
| 172 | |
| 173 | KRATOS_ERROR_IF_NOT(r_tensor_shape[0] == pContainer->size()) |
| 174 | << "Underlying container of the tensor data has changed size [ tensor data = " |
| 175 | << this->Info() << ", container size = " << pContainer->size() << " ].\n"; |
| 176 | |
| 177 | if constexpr(DataTypeTraits<data_type>::IsDynamic) { |
| 178 | // this zero value may be different from the Variable::Zero() |
| 179 | // in the case where the variable type is Variable<Vector> or Variable<Matrix>. |
| 180 | // Because, in these dynamic data type variables, Variable::Zero will create |
| 181 | // a zero sized vector or matrix, which is useless in the StoreData method. |
| 182 | // The following method creates correctly sized zero Vector or Matrix |
| 183 | // accordingly to be assigned to the entities, if they don't have the specified |
| 184 | // variable in their DataValueContainer. |
| 185 | const auto& zero = TensorAdaptorUtils::GetZeroValue(*pVariable, this->DataShape()); |
| 186 | |
| 187 | ContainerIOUtils::CopyFromContiguousDataArray<data_type>( |
| 188 | *pContainer, this->ViewData(), r_tensor_shape.data().begin(), |
| 189 | r_tensor_shape.data().begin() + r_tensor_shape.size(), |
| 190 | [pVariable, &zero](auto& rEntity) -> auto& { |
| 191 | return rEntity.Emplace(*pVariable, zero); |
| 192 | }); |
| 193 | } else { |
| 194 | ContainerIOUtils::CopyFromContiguousDataArray<data_type>( |
| 195 | *pContainer, this->ViewData(), r_tensor_shape.data().begin(), |
| 196 | r_tensor_shape.data().begin() + r_tensor_shape.size(), |
| 197 | [pVariable](auto& rEntity) -> auto& { |
| 198 | return rEntity.Emplace(*pVariable); |
| 199 | }); |
| 200 | } |
| 201 | } |
| 202 | }, this->GetContainer(), mpVariable); |
| 203 | } |
| 204 | |
| 205 | std::string VariableTensorAdaptor::Info() const |
| 206 | { |