2023-05-10 19:33:29 -04:00
|
|
|
/*
|
2024-10-15 11:47:13 -04:00
|
|
|
Copyright 2017-2024 Ian Jauslin
|
2023-05-10 19:33:29 -04:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-05-26 15:05:30 -04:00
|
|
|
#include "init.h"
|
|
|
|
#include "navier-stokes.h"
|
2022-05-27 16:09:17 -04:00
|
|
|
#include "io.h"
|
2022-05-26 15:05:30 -04:00
|
|
|
#include <math.h>
|
2024-12-11 15:48:11 -05:00
|
|
|
#include <stdlib.h>
|
2022-05-26 15:05:30 -04:00
|
|
|
|
|
|
|
// random initial condition
|
|
|
|
int init_random (
|
|
|
|
_Complex double* u0,
|
|
|
|
int K1,
|
|
|
|
int K2,
|
2024-12-11 15:48:11 -05:00
|
|
|
int seed
|
2022-05-26 15:05:30 -04:00
|
|
|
){
|
|
|
|
int kx,ky;
|
|
|
|
double x,y;
|
|
|
|
|
|
|
|
srand(seed);
|
|
|
|
|
|
|
|
// random init (set half, then the other half are the conjugates)
|
|
|
|
for(kx=0;kx<=K1;kx++){
|
2023-04-25 17:51:14 -04:00
|
|
|
for(ky=(kx>0 ? -K2 : 1);ky<=K2;ky++){
|
|
|
|
x=-0.5+((double) rand())/RAND_MAX;
|
|
|
|
y=-0.5+((double) rand())/RAND_MAX;
|
|
|
|
u0[klookup_sym(kx,ky,K2)]=x+y*I;
|
2022-05-26 15:05:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gaussian initial condition
|
|
|
|
int init_gaussian (
|
|
|
|
_Complex double* u0,
|
|
|
|
int K1,
|
2024-12-11 15:48:11 -05:00
|
|
|
int K2
|
2022-05-26 15:05:30 -04:00
|
|
|
){
|
|
|
|
int kx,ky;
|
|
|
|
|
2023-04-11 18:45:45 -04:00
|
|
|
for(kx=0;kx<=K1;kx++){
|
2023-04-25 17:51:14 -04:00
|
|
|
for(ky=(kx>0 ? -K2 : 1);ky<=K2;ky++){
|
2023-04-11 18:45:45 -04:00
|
|
|
u0[klookup_sym(kx,ky,K2)]=(kx*kx+ky*ky)*exp(-(kx*kx+ky*ky));
|
2022-05-26 15:05:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-05-27 16:09:17 -04:00
|
|
|
|
|
|
|
// Initialize from file
|
2023-04-24 12:06:35 -04:00
|
|
|
// txt input
|
|
|
|
int init_file_txt (
|
|
|
|
_Complex double* u0,
|
|
|
|
int K1,
|
|
|
|
int K2,
|
|
|
|
FILE* initfile
|
|
|
|
){
|
2023-04-24 12:12:20 -04:00
|
|
|
read_vec(u0, K1, K2, initfile);
|
2023-04-24 12:06:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// binary input
|
|
|
|
int init_file_bin (
|
2022-05-27 16:09:17 -04:00
|
|
|
_Complex double* u0,
|
|
|
|
int K1,
|
|
|
|
int K2,
|
|
|
|
FILE* initfile
|
|
|
|
){
|
2023-04-24 12:12:20 -04:00
|
|
|
read_vec_bin(u0, K1, K2, initfile);
|
2022-05-27 16:09:17 -04:00
|
|
|
return 0;
|
|
|
|
}
|