Read table from file

Numerical methods and mathematical models of Elmer
Tom
Posts: 20
Joined: 20 Jan 2016, 12:46
Antispam: Yes

Read table from file

Post by Tom »

Dear all,

I would like to read in a table from an ASCII file (two columns, space-separated). Peter's suggestion works but -- in my case -- only for boundary conditions. If I replace

Code: Select all

 
Heat Conductivity = Variable Temperature
   Real
      298 186
      373 195
      ...
      1073 92
   End
with

Code: Select all

 
Heat Conductivity = Variable Temperature
   Real
      include hc.dat
   End
I get the error message "ERROR:: SectionContents: Problem reading real keyword: heat conductivity: include hc.dat"
The .dat file is located in the same directory as the .sif file. Elmer version is 8.2. Can somebody help me please?

Tom
Tom
Posts: 20
Joined: 20 Jan 2016, 12:46
Antispam: Yes

Re: Read table from file

Post by Tom »

Ok, I found the reason: The line indents I used in the material section contained tabs. After replacing them with spaces everything works fine.

Tom
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Read table from file

Post by raback »

Hi Tom

Good, that you figured this out. It was quite puzzling. The parser should be somewhat more robust to deal with tabs too.

-Peter
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Read table from file

Post by annier »

Hi Tom,
For reference purpose , could you attach your hc.dat file herewith so that it could be a noteworthy illustration to make a SIF more concise.


Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
Tom
Posts: 20
Joined: 20 Jan 2016, 12:46
Antispam: Yes

Re: Read table from file

Post by Tom »

@Peter
Yes, that would be great. Also, I couldn't find any information about the include command except here in this forum.

@Anil
The hc.dat file isn't the problem actually, but the way you create line indents in your sif file. The line(s) with the include command must not contain tabs. I've attached the complete test project; material data is unrealistic for demonstration purpose.
Test_include_command.zip
(3.63 KiB) Downloaded 375 times
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Read table from file

Post by annier »

Hi Tom,
Thank you for uploading the illustration.

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
nacho_li
Posts: 1
Joined: 16 Jan 2019, 11:12
Antispam: Yes

Read table from file

Post by nacho_li »

Dear all,

I have the same problem asTom but I could not fix it. I tried wit Tom's file and still i am getting the same error
ERROR:: SectionContents: Problem reading real keyword: heat source: include test.txt

Here is a copy of my case.sif

Code: Select all

Body Force 1
  Name = "HeatIn"
  Heat Source = Variable Time;real;include test.txt;End
End
my test.txt is like this:

Code: Select all

0 0
1 1
2 2

If i just write the numbers there is not problem

Code: Select all

Body Force 1
  Name = "HeatIn"
  Heat Source = Variable Time;real;0 0;1 1;2 2;End
End

I hope that anyone can help me with it.

Thank you all in advance

Regards,
Ignacio
Attachments
test.txt
(13 Bytes) Downloaded 275 times
solver_log.txt
(7.86 KiB) Downloaded 241 times
case.sif
(4.45 KiB) Downloaded 271 times
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Read table from file

Post by mzenker »

Hi,

I would not really expect it, but could it be a \CR\LF vs. \LF problem?
Your test.txt contains \CR\LF at the line ends, Tom's dat file only \LF.
If really this is the case, this should be fixed IMHO since nobody expects a parser to have a problem with that, these days...

HTH,
Matthias
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Read table from file

Post by raback »

Hi

It seems that the syntax with a semicolon causes the problem. This does not work:

Code: Select all

Body Force 1
  Name = "HeatIn"
  Heat Source = Variable Time;real;include test.txt;End
End
but this does:

Code: Select all

Body Force 1
  Name = "HeatIn"
  Heat Source = Variable Time;real;
    include test.txt 
  End 
Didn't look at the parser in detail but my guess is that the recursive call to continue reading from an other file assumes that the include statement is an a clean line. Not optimal, I agree.

If you use the GUI you can pres "Enter" to launch an edit window where the multiline values can be edited. Genereally semicolon is indeed intepreted as an alternative to newline.

-Peter
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Read table from file

Post by mzenker »

The problem is that a multiline value is converted to a one-liner with semicolons when the edit window is closed...
Post Reply