change the value of item modul

21 views
Skip to first unread message

Lance Zhang

unread,
Jul 17, 2023, 5:57:30 PM7/17/23
to deal.II User Group
Hello,

I would like to change the value of    set Shear modulus   to 1e6 using a parameter in function. so I can control the value of modulus and this parameter will be used and changed in each iteration of loop.

There are two ideas
1st)I want to change the value of modulus and the new value will be written back to prm file.And in next step the file will read as input to execute the next steps.

2nd)I would like to create a object prm and changed the value of modulus,but not written to back to  prm file,use prm object in next steps;

in function:
           prm.parse_input("parameters.prm");
  
           prm.enter_subsection("Material properties");

           prm.set("Shear modulus", x[0]);

          prm.leave_subsection();

          prm.print_parameters("parameters.prm",dealii::ParameterHandler::Text);

         {
          deallog.depth_console(0);

          Parameters::AllParameters parameters("parameters.prm");
          parameters.mu=x[0];
//        x_density_percell=parameters.mu;(I found there are errors in umpack)
          if (parameters.automatic_differentiation_order == 0)
         {
          std::cout << "Assembly method: Residual and linearisation are computed manually." << std::endl;

          // Allow multi-threading
         // Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv,
           //                                                   dealii::numbers::invalid_unsigned_int);

          typedef double NumberType;
          Solid<dim,NumberType> solid_3d(parameters);
             solid_3d.run();
   }
 }

The information above is what I wrote,but the errors come out . I am not quite familiar with prm part,I am still learning dealii for more knowledge and skills.

May I know if anyone could provide any hint or suggestions?Which idea is better  for implementation?


Thanks in advance!
Best regards
Lance

#>>>>>>>>>>>>>>>>>>>>>>
# Listing of Parameters
# ---------------------
subsection Assembly method
  # The automatic differentiation order to be used in the assembly of the linear system.
  # Order = 0: Both the residual and linearisation are computed manually.
  # Order = 1: The residual is computed manually but the linearisation is performed using AD.
  # Order = 2: Both the residual and linearisation are computed using AD.
  set Automatic differentiation order = 0
end

subsection Finite element system
  # Displacement system polynomial order
  set Polynomial degree = 1

  # Gauss quadrature order
  set Quadrature order  = 2
end


subsection Geometry
  # Number of elements per long edge of the beam
  set Elements per edge  =20

  # Global grid scaling factor
  set Grid scale         = 1e-3
end


subsection Linear solver
  # Linear solver iterations (multiples of the system matrix size)
  set Max iteration multiplier  = 10

  # Linear solver residual (scaled by residual norm)
  set Residual                  = 1e-6

  # Preconditioner type
  set Preconditioner type        = ssor

  # Preconditioner relaxation value
  set Preconditioner relaxation  = 0.65

  # Type of solver used to solve the linear system
  set Solver type               = Direct
end


subsection Material properties
  # Poisson's ratio
  set Poisson's ratio = 0.3

  # Shear modulus
  # set Shear modulus   = 0.4225e6
   set Shear modulus   = 1e6
end


subsection Nonlinear solver
  # Number of Newton-Raphson iterations allowed
  set Max iterations Newton-Raphson = 10

  # Displacement error tolerance
  set Tolerance displacement        = 1.0e-6

  # Force residual tolerance
  set Tolerance force               = 1.0e-9
end


subsection Time
  # End time
  set End time       = 1

  # Time step size
  set Time step size = 0.1
end

Wolfgang Bangerth

unread,
Jul 17, 2023, 6:03:04 PM7/17/23
to dea...@googlegroups.com
On 7/17/23 15:57, Lance Zhang wrote:
>
> The information above is what I wrote,but the errors come out .

Lance -- nobody can help you if you don't say what exactly the error is.
Carefully reading the error message often is 50% of the process of figuring
out what the problem is.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/


Lance Zhang

unread,
Jul 17, 2023, 6:19:49 PM7/17/23
to deal.II User Group
Hello Wolfgang,

The error shows below:

[ 66%] Built target cook_membrane
[100%] Run cook_membrane with Release configuration
///////////////////////////////////////////////////
// Test the GCMMA algorithm
///////////////////////////////////////////////////
terminate called after throwing an instance of 'dealii::ParameterHandler::ExcNoSubsection'
  what():  
--------------------------------------------------------
An error occurred in line <1848> of file <./source/base/parameter_handler.cc> in function
    void dealii::ParameterHandler::scan_line(std::string, const string&, unsigned int, bool)
The violated condition was:
    skip_undefined || entries->get_child_optional( get_current_full_path(subsection))
Additional information:
    Line <3> of file <parameters.prm: There is no such subsection to be
    entered: Assembly method
--------------------------------------------------------

make[3]: *** [CMakeFiles/run.dir/build.make:71: CMakeFiles/run] Aborted (core dumped)
make[2]: *** [CMakeFiles/Makefile2:172: CMakeFiles/run.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:179: CMakeFiles/run.dir/rule] Error 2
make: *** [Makefile:163: run] Error 2

Best regards
Lance

Wolfgang Bangerth

unread,
Jul 17, 2023, 6:35:25 PM7/17/23
to dea...@googlegroups.com
On 7/17/23 16:19, Lance Zhang wrote:
>
> terminate called after throwing an instance of
> 'dealii::ParameterHandler::ExcNoSubsection'
>   what():
> --------------------------------------------------------
> An error occurred in line <1848> of file <./source/base/parameter_handler.cc>
> in function
>     void dealii::ParameterHandler::scan_line(std::string, const string&,
> unsigned int, bool)
> The violated condition was:
>     skip_undefined || entries->get_child_optional(
> get_current_full_path(subsection))
> Additional information:
>     Line <3> of file <parameters.prm: There is no such subsection to be
>     entered: Assembly method
> --------------------------------------------------------

Lance: If you run this in the debugger (or put some print statements into your
code), I bet that you will see that the problem comes from calling
prm.parse_input("parameters.prm");
and that the error is exactly described by the message above: When you
declared all of your parameters, you have never mentioned that there is a
subsection "Assembly method", but that your file "parameters.prm" has a
subsection Assembly method
statement.
Reply all
Reply to author
Forward
0 new messages