I don't know if it is the optimal way but I would use the following approach
1. Read tensor components as Patterns::List 2. Use get <https://www.dealii.org/current/doxygen/deal.II/classParameterHandler.html#a91cfbaca954f444047302446a4e87125> method of ParameterHandler to read all tensor components as one string into a string variable 3. Use split_string_list <https://www.dealii.org/current/doxygen/deal.II/namespaceUtilities.html#a0a2b9ceded96f25b47eccd7c177dc67e> in the Utilities namespace to split the string into individual components (still all components are strings) 4. Convert string-type components into doubles using string_to_double <https://www.dealii.org/current/doxygen/deal.II/namespaceUtilities.html#ab3177021843ad87857e6f8c5d98d29a5> in the Utilities namespace 5. Use Tensor <https://www.dealii.org/current/doxygen/deal.II/classTensor.html#a6118e90e58ca4041ba452ab647db0b29> (const Tensor <https://www.dealii.org/current/doxygen/deal.II/classTensor.html>< rank_, dim, OtherNumber > &initializer) to construct the tensor On Tue, Apr 14, 2020 at 11:12 AM Paras Kumar <[email protected]> wrote: > Dear deal.II community, > > I am trying to read a second order tensor from a .prm file using the > ParameterHandler functionalities. The tensor (for dim=3) is set in .prm > file as > > set macro def grad = 1.2|0.0|0.0|0.0|1.1|0.0|0.0|0.0|1.4 > > and is currently read as a string using > 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]); > > > I am curious to know, if there is a smarter way (avoiding this manual > copying by looping over the tensor entries) to do so using some other type > of dealii::Patterns object or some other way. > > Thanks in advance and best regards, > Paras Kumar > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/dealii/595804dd-818f-4fd6-86ba-f4e3d7d378a6%40googlegroups.com > <https://groups.google.com/d/msgid/dealii/595804dd-818f-4fd6-86ba-f4e3d7d378a6%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/CAGCgw4BULgRKA3sDWegpGm%3Dhxy_81OdoNJSmMdo2EEf3_2um1A%40mail.gmail.com.
