Pascal Languague

  • Hey - turns out IRC is out and something a little more modern has taken it's place... A little thing called Discord!

    Join our community @ https://discord.gg/JuaSzXBZrk for a pick-up game, or just to rekindle with fellow community members.

nightwing`

? taguZ! ? Pato`
May 16, 2006
4,180
36
Portugal
Pascal Language

hi there :wave:

I'm sorry if I'm posting this on the wrong place.


I'm here to ask for your help :D

I have to do a program that can do the calculation of the deflection caused by one or more loads on a beam (like on the image).
have it working for 1 load but I want it to calculate for more.
need to use Arrays but can't get it to work properly :S


can you guys that a look at the code and try to tell what I'm supose to do?


Code:
program calculo_flexa;

 uses crt;
 Const MaxSec=1000;
       MaxNcp=500;
    Type Tab1=Array[0..MaxSec] of Real;
         Tab2=array[1..MaxNCP]of real;



VAR  K,E,MI,b,L,alfa,beta,lambda:real;
     P:real;
     a,fx,x:real;
     SomaFx:real;
     i,NSEQ,NCP:integer;
     Sair:Char;


{================================ Erro  ====================================}
Procedure Erro(Mensagem:String);
Begin

TextColor(LightRed);
gotoxy(06,13);Writeln('Valor Incorrecto: ' + Mensagem);
TextColor(White)
End;

{========================== Nome Instituição ================================}
PROCEDURE ISEL(Cor:Integer);
Begin
       textcolor(lightgreen);
     Gotoxy(54,03); Write(' ..... ..... ..... .    ');
     Gotoxy(54,04); Write('   .   .     .     .    ');
     Gotoxy(54,05); Write('   .   ..... ...   .    ');
     Gotoxy(54,06); Write('   .       . .     .    ');
     Gotoxy(54,07); Write(' ..... ..... ..... .....');
     Gotoxy(54,09); Write('Instituto   ');
     Gotoxy(54,11); Write('      Superior ');
     Gotoxy(54,13); Write('          Engenharia  ');
     Gotoxy(54,15); Write('                 Lisboa');
End;


{================== Bloquer o Programa em Caso de Erro na Password ===========}
Procedure Bloquear;
  Var x:Integer;
  Begin
     X:=1;
     While X=1 DO Begin
                   Gotoxy(Random(77),Random(32));
                   TextColor(random(40));
                   Write('error')
                  End;

  End;

{================= Registar a Tecla escolhida e Escrever um "*"  =============}
Procedure Tecla(VAR C:Char);
  Begin
       TextColor(Black);
       C:=Readkey;
       C:=UpCase(C);
       TextColor(Yellow); Write('*')
  End;

{================== Validar Password maximo 3 tentativas =====================}
Procedure Password;
  Var Chave,Pass:String[4];
      C1,C2,C3,C4,C5:Char;
      Conta:Integer;
  Begin
     Chave:='LC11N';
     Conta:=1;
     TextBackground(Black);
     Repeat
       TextColor(lightred);
       Gotoxy(10,10); Write(' ':40);
       Gotoxy(10,10); Write('Tentativa -',Conta,'- Password ---> ');

       Tecla(C1);
       Tecla(C2);
       Tecla(C3);
       Tecla(C4);
       Tecla(C5);

       Pass:=C1+C2+C3+C4+C5;
       Conta:=Conta+1
     Until (Chave=Pass) or (Conta=4);

     IF Chave<>Pass Then Bloquear

  End;

{========== Escrever os caracteres escolhidos na posicao selecionada =========}
Procedure Tracos(Col,Lin,Simbolo:Integer);
Begin
   Gotoxy(Col,Lin); Write(Char(Simbolo))
End;


{====== Desenhar a Moldura do Trabalho...Designacao, autores, data, ISEL,..===}
Procedure Moldura(Cor:Integer);

Var i:Integer;

Begin
    ISEL(LightGreen);


    TextColor(lightblue);
    For i:=1 TO 78 DO Tracos(i+1,01,205);
    For i:=1 TO 78 DO Tracos(i+1,16,205);
    For i:=1 TO 78 DO Tracos(i+1,25,205);

    For i:=1 TO 24 DO Tracos(01,i+1,186);
    For i:=1 TO 24 DO Tracos(50,i+1,186);
    For i:=1 TO 24 DO Tracos(80,i+1,186);

    TextColor(lightblue);
    Tracos(01,01,201);
    Tracos(01,25,200);

    Tracos(80,01,187);
    Tracos(80,25,188);

    Tracos(50,01,203);
    Tracos(50,25,202);

    Tracos(01,16,204);
    Tracos(80,16,185);

    Tracos(50,16,206);


    Gotoxy(07,05);  TextColor(lightred);Write('- - - - - - - - - - - - - - - - - - - - ');
    Gotoxy(07,06); TextColor(lightred); Write('|                                     | ');
    Gotoxy(07,07);  TextColor(lightred);Write('- - - - - - - - - - - - - - - - - - - - ');
     Gotoxy(08,06);TextColor(yellow);Write('*Viga sobre apoio elastico continuo*');
   end;

 {======================== Pedir os Dados  da Viga ===========================}
procedure intdados_viga(var L,b,K,E,MI:real; var alfa,beta,Lambda:real);
  begin
  Clrscr;
   textcolor(white);


   repeat
   Gotoxy(06,03);Write('Largura da Viga (b) ? ');
   Readln(b);
   IF b<=0 THEN Erro ('Atencao: b > 0')
   Until b>0;

    Repeat
   Gotoxy(06,04);Write('Modulo do Solo (K) ? ');
   Readln(K);
   IF K<=0 THEN Erro ('Atencao: K > 0')
   Until K>0;

   Repeat
   Gotoxy(06,05);Write('Modulo de Elasticidade (E) ? ');
   Readln(E);
   IF E<=0 THEN Erro ('Atencao: E > 0')
   Until E>0;

   Repeat
   Gotoxy(06,06);Write('Momento de Inercia (MI) ? ');
   Readln(MI);
   IF MI<=0 THEN Erro ('Atencao: MI > 0')
   Until MI>0;

   Beta:=K*B;
   Alfa:=exp((1/4)*ln(Beta/(4*E*MI)));
   Lambda:=2*Pi/Alfa;
   
   Repeat
   Gotoxy(06,02);Write('Comprimento da Viga (L) ? ');
   Readln(L);
   IF (L<=2.5*Lambda) THEN Erro ('Atencao: Comprimento Insuficiente')
   Until L>2.5*Lambda;


end;

{=======================  Pedir os Dados  da Carga ===========================}
procedure intdados_carga ( var P,a:real ; var NSEQ:integer);


 Var Texto_MaxSec:String;
  i:integer;
begin
Clrscr;
textcolor(white);

Str(MaxSec,Texto_MaxSec);

   Gotoxy(06,02);Write('Indique o numero de Cargas Pontuais? ');

    Readln(NCP);

    for i:=1 to NCP do Begin

    Repeat
  Gotoxy(06,03);DelLine;
  Gotoxy(06,03);Write('Indique o valor da Carga  ',i:2,'?     ');
      Readln(p);

    IF P=0 THEN Erro ('Atencao: Carga <> 0')
   Until P<>0;
    end;

    for i:=1 to NCP do Begin

    Repeat
    Gotoxy(06,04);DelLine;
   Gotoxy(06,04);Write('Distancia da origem á Carga',i:2,' ? ');
Readln(a);

   IF a<0 THEN Erro ('Atencao: Distancia >= 0')
   Until a>=0;
   end;



   Gotoxy(06,05);Write('Numero de Seccoes Equidistantes (NSEQ) ? ');



Repeat
Readln(NSEQ);
IF (NSEQ<=0) or (NSEQ>MaxSec)
THEN Erro('Atencao: NSEQ > 0 e NSEQ<=' + Texto_MaxSec);
Until (NSEQ>0) and (NSEQ<=MaxSec)

end;

{========================= calculo da flecha =================================}

Procedure calc_flecha(NSEQ:Integer;L,P,a,x,Beta,Alfa:Real);

Var Q,B1,B2,dx,Fx:Real;
    i:Integer;

    Begin
            Q:=(P*Alfa)/(2*Beta);
            B1:=Alfa*(a-x);
            B2:=Alfa*(x-a);
            dx:=L/(NSEQ);

        For i:=0 to NSEQ do begin
                               If(x>=0) and (x<=a) then
                                                        Fx:=Q*exp(-B1)*(sin(Alfa*(a-x))+cos(Alfa*(a-x)));
                               If(x>a) and (x<=L) then
                                                        Fx:=Q*exp(-B2)*(sin(Alfa*(x-a))+cos(Alfa*(x-a)));
                               x:=i*dx;
                           end;

    End;





{============================ Autores do programa=============================}
PROCEDURE Autores;
Begin
     TextColor(yellow);
     Gotoxy(06,18); Write('Carlos Luis Pedroso Filipe       - 37738   ');
     Gotoxy(06,20); Write('Henrique Manuel Narciso Esgueira - 37740  ');
     Gotoxy(06,22); Write('Tiago Filipe Camilo Alves        - 37751');
     Gotoxy(06,24); Write('Data:  /  /           ');



End;



{=============== Perguntar se quer abandonar programa ========================}
Procedure SairPrograma(VAR Sair:Char);
Begin
Clrscr;
Repeat
Gotoxy(08,22);
Write('Pretende Abandonar o Programa (S/N) ? ');
Sair:=Readkey;
Sair:=UpCase(Sair);
Until sair IN ['S','N']
End;

 {=======================-_-= -*Bloco Principal*- =-_-=======================}

begin

     Moldura(Lightblue);
   {  password;}
     Autores;

     Writeln;
     TextColor(lightred);
     Gotoxy(55,21); write(' Prima qualquer tecla');
     Gotoxy(55,22); Write('para continuar programa');
     Readln();

     Repeat
     Clrscr;
     intdados_viga(L,b,K,MI,E,alfa,beta,lambda);
     intdados_carga(P,a,NSEQ);

     calc_flecha(NSEQ,L,P,a,x,Beta,Alfa);
     SairPrograma(sair)
     Until Sair='S'

end.

that's what I need to do:
1) Read data from the beam: K, B, E, MI (positive values);
Calculate alfa, beta and lambda;
Read as: L (L> 2.5*lambda)

2) Read data load: P and (a is a positive value);

3) Read number of equidistant sections: NSEQ

4) For each section (0 to NSEQ) calculate:
4.1) Distance x to the origin O;
4.2) Arrow F for the distance x ;

5) For each section (0 to NSEQ) write on the screen:
5.1) Distance x to the origin O;
5.2) Arrow F for the distance x ;

and also have calculate when the deflection is zero,
ask if the user wants to save or not the results in a file,
make a graph..


where:
P - Value of Load
L - Length of Beam
a - distance between source and point of application of load
x - section corresponding to the point of application of load
b - beam width
K - Soil Module
E - modulus
MI - Moment of inertia of section
NSEQ - Number of Sections Equidistant
NCP - Number of point charges
 

Attachments

  • flecha.jpg
    flecha.jpg
    14.2 KB · Views: 101
Last edited:
If I understand it correctly you are calculating the deflection of a beam resting on an elastic fundation (soil) due to discrete loads spread around the beam?

Effectively to be solved piece wise using a bespoke (finite) element formulation? If that is the case you end up having to solve a system of equations and I don't see that. So that is effectively the problem with your array?

You basically apply an analytical formula here: calculo da flecha

So you either have to write a code to solve effectively a finite element forumlation of your problem or you do the derivation with your bare hands... I will look later today if I can find an analytical solution in a closed form. Not sure if it exists like that. More importantly what are the boundary conditions at the end of the beam?

You can check standard references like Roarke for an idea of an analytical extension to your problem. But I don't have that book at home (I do at work)
 
Last edited:
Incidentally just dawns on me when you have calculated the deflection of the points correctly along the beam you can interpolate them using a cubic-spline function. Since a cubic spline is always the exact solution of a deformed (uniform) beam. 3rd order solution to a 4th order uniform differential equation.... the soil is just a linear part of the normal 4th order equation.
 
If I understand it correctly you are calculating the deflection of a beam resting on an elastic fundation (soil) due to discrete loads spread around the beam?
yes that's right.


I gonna try to explain better what I need to do (kinda hard beacuse my english is still too bad):

(...)
- ask the user how many loads he wants (NCP);
- the value of the loads (P);
- the distance between the loads and the "source" aka 0 meters (a);
- the number of Sections Equidistant (NSEQ);
- then calculate the deflection in each sections equidistant caused by each load (Fx); (that's the problem)


the code I posted before is just working for 1 load, beacuse it's not saving the values for more then 1 load.
I had it working before, all values of loads and theirs distance to the source were being recorded in arrays.
now the problem is, how I can calculate the defection for that values saved on the array?


this is the expression that the professor gave to us:

Code:
{these 3 is just to simplify the big one below}
    Q:=(P*Alfa)/(2*Beta);
     B1:=Alfa*(a-x);
     B2:=Alfa*(x-a);
          
{this one to calculate the length of sections)
  dx:=L/(NSEQ);
   x:=i*dx;         

{this is the one that's gonna calculate the deflection (Fx) for each section)
        For i:=0 to NSEQ do begin
                               If(x>=0) and (x<=a) then
                                                        Fx:=Q*exp(-B1)*(sin(Alfa*(a-x))+cos(Alfa*(a-x)));
                               If(x>a) and (x<=L) then
                                                        Fx:=Q*exp(-B2)*(sin(Alfa*(x-a))+cos(Alfa*(x-a)));
                             
                           end;



I dunno how to adapt the expression to calculate it using the values of the arrays :s


probably I'm not explaining very well :(
 
i really want to do this :D

NERDSSSSSSSSSSSSSSSSSSSSSSSS :P j/king
 
lol, I'm studying civil engineering but I have a discipline "Computers and Programming".

1st time I'm doing a thing like this.
 
Well I have a degree in mechanical engineering and mathematics and work as an engineer for a university doing stuff like this all the time :) So it does interest me. Anyway need to eat first and then will have a look at it. Have a look at this by the way: http://www.ejge.com/2009/Ppr09119/Ppr09119.pdf

Seems to be what you have (normalised). Applying the load gives a linear deflection? That is, the relation between load and displacement is linear (Hooke like) then the problem reduces to N loadcases for N loads and then a simple superposition. That would be where your array comes in. You need to produce (indeed) an array with the deflection of each point and then call a routine N-times that calculates each individual deflection case (for the whole beam) and simply keep adding each individual deflection to the array. Hope I make sense.... The other way round is to cycle for each point on the beam and add for all the cases the deflection.
 
Well I have a degree in mechanical engineering and mathematics and work as an engineer for a university doing stuff like this all the time :) So it does interest me. Anyway need to eat first and then will have a look at it. Have a look at this by the way: http://www.ejge.com/2009/Ppr09119/Ppr09119.pdf

Seems to be what you have (normalised). Applying the load gives a linear deflection? That is, the relation between load and displacement is linear (Hooke like) then the problem reduces to N loadcases for N loads and then a simple superposition. That would be where your array comes in. You need to produce (indeed) an array with the deflection of each point and then call a routine N-times that calculates each individual deflection case (for the whole beam) and simply keep adding each individual deflection to the array. Hope I make sense.... The other way round is to cycle for each point on the beam and add for all the cases the deflection.


o/ rocket scientist at work!
 
people always make a fuzz about the most obvious answers ... if it is 42 it is 42 no need to argue or discuss the subject ;)