Author Topic: Programmatic change of parameters via loop with a termination criterion  (Read 6077 times)

serkuz

  • Jr. Member
  • **
  • Posts: 26
Dear Prof. Taylor, dear FEAP community,

I try to write a macro, that varies the parameters up to a termination criterion  and performs a FE calculation . The main file should have the following form:

Code: [Select]
PARA
  my_param = 10
POPT, Ifile, my_param

END
INTEractive

STOP

In the "Ifile" the young modulus is kept variable:
Code: [Select]
FEAP * * 4-element patch test
  9,4,1,2,2,4
MATErial, 1
  SOLId
    PLANE STRAIN
    ELAStic ISOTropic my_param 0.25
...
END

In "pcontr.f" I created a block, which reads the entries from "POPT":
Code: [Select]
...
 elseif (pcomp (titl (1: 4), 'pop', 4)) then
          Call acheck (titl, yyy, 20, 80, 160)
          Read (yyy, 1000, err = 900, end = 911) titl (1: 4), dnam, dnam2, dnam3
          Call popt (yyy, dnam, dnam2, dnam3)
...

The "POPT" subroutine as a minimum example looks as follows:
Code: [Select]
      SUBROUTINE popt(value0, value1, value2, value3)
      implicit none
     
      Include 'iodata.h'
      Include 'conval.h'

      character (*) value0, value1, value2, value3
      logical error, prt
      real * 8 val, val2

      save
      Error = .false.
      Prt = .true.
     
      call getparam (value2, val, error, prt)

      do while (val <100)
          val = val + 10.0
          val2 = val
          call setparam (value2, val2, prt)
          call pincld (value1)
      end do
      END

For me the problem is that the old output files are overwritten with new values. That is, concretely, that e.g. "Ofile_001" to "Ofile_010" same young modulus and always take the last ones.

I suspect that with each call from the include subroutine the old output file is overwritten with new values. How can you avoid this?

Thanks in advance.


Best regards
serkuz

Prof. R.L. Taylor

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 2649
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #1 on: November 04, 2016, 08:23:11 AM »
If you want to vary the parameter then the easiest way is to use two files

The main file sets the parameter and calls the solve file

parameter
  aa = 1

include Irun_problem

parameter
  aa = 2

include Irun_problem

etc.

The file Irun_problem is complete except for the value of the parameter(s)

this also keeps the solution files separately.

serkuz

  • Jr. Member
  • **
  • Posts: 26
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #2 on: November 04, 2016, 08:51:00 AM »
Dear Prof. Taylor,

Thank you for the fast answer.
The problem is that I want to determine the parameters with an optimization algorithm and do not know how many calculations I need for it.

The procedure is as follows:
1. my_param : = 1
2. Make FE calculation
3. If the solution is bad with my_param, then use optimization algorithm
4. Vary my_param  until the termination criterion is reached
5. my_param : = new value from the optimization


Best regards
serkuz

Prof. R.L. Taylor

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 2649
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #3 on: November 04, 2016, 11:23:14 AM »
Can the routine: call setparam ('aa', value, prt) help you?  This call would set the parameter 'aa' to the value in 'value' (which is real*8 kind).  If 'prt' = .false' the value is not echoed to any outputs.

serkuz

  • Jr. Member
  • **
  • Posts: 26
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #4 on: November 07, 2016, 01:13:52 AM »
Can the routine: call setparam ('aa', value, prt) help you?  This call would set the parameter 'aa' to the value in 'value' (which is real*8 kind).  If 'prt' = .false' the value is not echoed to any outputs.


Dear Professor Taylor,

setparam was also my first idea and the routine worked very well. However, I have problems with the output. I will give an example to clarify my problem.
If the parameter E1 (but can be any other parameter) is the Young's modulus of any material. I would now like to change E1 (currently a trivial change, without algorithms) and perform the calculation:
Code: [Select]
...
call getparam(e1, val, error, prt)
      do while (val <100)
          val = val + 50
          val2 = val
          call setparam (e1, val2, prt)
          call pincld (Ifile_name)
      end do
...
As output I get two files, but as the Young's modulus have only the second value, thus:

1. output file (Ofile_name001):
...     

T w o   D i m e n s i o n a l   S o l i d   E l e m e n t

     M e c h a n i c a l   P r o p e r t i e s

          Plane Strain  Analysis

          Modulus E        1.00000E+02
          Poisson ratio    0.25000
...


2. output file (Ofile_name002):
...     

T w o   D i m e n s i o n a l   S o l i d   E l e m e n t

     M e c h a n i c a l   P r o p e r t i e s

          Plane Strain  Analysis

          Modulus E        1.00000E+02
          Poisson ratio    0.25000
...


Best regards
serkuz

Prof. R.L. Taylor

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 2649
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #5 on: November 07, 2016, 10:56:28 AM »
You may be able to do this with a call to pnewprob (in the program directory).  If not a direct call look at the file to see what can be used to save the current file and start a new one.

serkuz

  • Jr. Member
  • **
  • Posts: 26
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #6 on: November 09, 2016, 06:07:29 AM »
You may be able to do this with a call to pnewprob (in the program directory).  If not a direct call look at the file to see what can be used to save the current file and start a new one.
Dear Professor Taylor,
In the "program" folder I have no file pnewprob , but pnewpr.f. Is this the same thing?
Best regards
serkuz


P.S.: I'm using FEAP 8.2

Prof. R.L. Taylor

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 2649
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #7 on: November 09, 2016, 08:07:44 AM »
No, ver8.2 does. To support what I described. 

You still can use setparam but will hav to manage files yourself.

serkuz

  • Jr. Member
  • **
  • Posts: 26
Re: Programmatic change of parameters via loop with a termination criterion
« Reply #8 on: November 10, 2016, 05:43:00 AM »
Dear Professor Taylor,

Thank you for your suggestions.

Best Regards
serkuz