parameterHandler.declare_entry(
"macro def grad",
"1.0|1.0|1.0|1.0",
dealii::Patterns::Anything(),
"Macroscopic deformation gradient for homogenization");
auto temp = parameterHandler.get("macro def grad");
std::vector<std::string> defGradComps;
boost::algorithm::split(defGradComps,
temp,
boost::algorithm::is_any_of("|"));
Assert(defGradComps.size() == dim * dim,
dealii::ExcDimensionMismatch(defGradComps.size(),
dim * dim));
for (mncfrac::utilities::UnsignedIntType i = 0; i < dim; ++i)
for (mncfrac::utilities::UnsignedIntType j = 0; j < dim; ++j)
this->problemSpecificParameters_.macroDefGrad_[i][j] =
std::stod(defGradComps[i * dim + j]);
--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/595804dd-818f-4fd6-86ba-f4e3d7d378a6%40googlegroups.com.
I don't know if it is the optimal way but I would use the following approach
- Read tensor components as Patterns::List
- Use get method of ParameterHandler to read all tensor components as one string into a string variable
- Use split_string_list in the Utilities namespace to split the string into individual components (still all components are strings)
- Convert string-type components into doubles using string_to_double in the Utilities namespace
- Use Tensor (const Tensor< rank_, dim, OtherNumber > &initializer) to construct the tensor
#include <deal.II/base/tensor.h>
#include <deal.II/base/parameter_handler.h>
#include <deal.II/base/utilities.h>
#include <string>
#include <iostream>
#include <sstream>
using namespace dealii;
int main() {
// Let's read this tensor from an istringstream. You may read it from istream in your
// application
std::istringstream is("set Tensor3x3 = 11, 12, 13, 21, 22, 23, 31, 32, 33");
// Now let's set up the ParameterHandler object. Since you are reading 3x3 tensor, you are
// dealing with 9 components and the default value should also have 9 components (here 9
// zeros) in it
ParameterHandler prm;
using Patterns::List;
using Patterns::Double;
prm.declare_entry("Tensor3x3",
"0,0,0,0,0,0,0,0,0",
List(Double(), 9, 9),
"Tensor components");
// Let's read it in now
prm.parse_input(is);
const std::string tensorString = prm.get("Tensor3x3");
// Now let's split the string into individual components
const std::vector<std::string> tensorComponentsString =
Utilities::split_string_list(tensorString);
// Now go over each component, convert it into double and put it in the tensor
Tensor<2, 3> tensor;
unsigned int counter = 0;
for (unsigned ii = 0; ii < tensor.dimension; ++ii) {
for (unsigned jj = 0; jj < tensor.dimension; ++jj) {
tensor[ii][jj] = Utilities::string_to_double(tensorComponentsString[counter++]);
}
}
// Let's check if we read the tensor correctly
for (unsigned ii = 0; ii < tensor.dimension; ++ii) {
for (unsigned jj = 0; jj < tensor.dimension; ++jj) {
std::cout << "component [" << ii << ", " << jj << " ] = "
<< tensor[ii][jj] << std::endl;
}
}
}
Enter code here...--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/2dc41828-0ca7-4673-ab2b-3b9803e4110b%40googlegroups.com.
Thank you. This really shortens the code. Is it also possible to set the delimiter to a user desired value, say "|" instead of ",".
Also, where exactly is the procedure for conversion from string to deali::Tensor or some other type say std::vector<double> defined? I could not find it in the source code.Best regards,Paras
On Tuesday, August 4, 2020 at 6:15:47 PM UTC+2, Paras Kumar wrote:Hi,Could you please provide an MWE to describe how the Patterns::Convert::to_value() function would work in this case.Is it must to use prm.add_parameter() to be able to do so? I usually use prm.declare_entry() and prm.get().Best regards,ParasOn Wednesday, April 15, 2020 at 6:01:53 PM UTC+2, Luca Heltai wrote:Currently, this is also the simplest way:Tensor<rank, dim> tens;prm.add_parameter("Tensor", tens);Take a look at the documentation of the add parameter method.Patterns::Tools::to_string(tens);AndPatterns::Tools::to_value
Are also available to simplify what you want to achieve.Alternatively: Patterns::Tools::Convert offers ways to construct default Patterns for many types, including Tensors.Best,Luca
--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/01e0068e-205b-4984-a5e8-f9d23ab1bb72o%40googlegroups.com.